当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript SPHttpClient.get方法代码示例

本文整理汇总了TypeScript中@microsoft/sp-http.SPHttpClient.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript SPHttpClient.get方法的具体用法?TypeScript SPHttpClient.get怎么用?TypeScript SPHttpClient.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@microsoft/sp-http.SPHttpClient的用法示例。


在下文中一共展示了SPHttpClient.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: reject

		return new Promise<string>((resolve,reject) => {
			let endpoint = Text.format("{0}/_api/web/lists(guid'{1}')/Fields?$select=IsTermSetValid,TermSetId&$filter=InternalName eq '{2}'", webUrl, listId, fieldInternalName);
			this.spHttpClient.get(endpoint, SPHttpClient.configurations.v1).then((response: SPHttpClientResponse) => {
				if(response.ok) {
					response.json().then((data:any) => {
						let fields:any[] = data.value;
						let fieldTermSetId = null;

						if(fields.length > 0) {
							let field = fields[0];

							if(field.IsTermSetValid && !isEmpty(field.TermSetId)) {
								fieldTermSetId = field.TermSetId;
							}
						}
						resolve(fieldTermSetId);
					})
					.catch((error) => { reject(error); });
				}
				else {
					reject(response);
				}
			})
			.catch((error) => { reject(error); }); 
        });
开发者ID:,项目名称:,代码行数:25,代码来源:

示例2: and

		return new Promise<IListTitle[]>((resolve,reject) => {
			let endpoint = Text.format("{0}/_api/web/lists?$select=Id,Title&$filter=(IsPrivate eq false) and (IsCatalog eq false) and (Hidden eq false)", webUrl);
			this.spHttpClient.get(endpoint, SPHttpClient.configurations.v1).then((response: SPHttpClientResponse) => {
				if(response.ok) {
					response.json().then((data: any) => {
						let listTitles:IListTitle[] = data.value.map((list) => { return { id: list.Id, title: list.Title }; });
						resolve(listTitles.sort((a,b) => { return Number(a.title > b.title); }));
					})
					.catch((error) => { reject(error); });
				}
				else {
					reject(response);
				}
			})
			.catch((error) => { reject(error); }); 
        });
开发者ID:,项目名称:,代码行数:16,代码来源:

示例3: getItems

 // private _listItems: IListItem[];
 public getItems(requester: SPHttpClient, siteUrl: string, listName: string): Promise<any[]> {
     switch(listName) {
         case "GenericList":
             let items: IListItem[];
             // tslint:disable-next-line:max-line-length
             return requester.get(`${siteUrl}/_api/web/lists/getbytitle('${listName}')/items?$select=Title,Id,Modified,Created,Author/Title,Editor/Title&$expand=Author,Editor`,
             SPHttpClient.configurations.v1,
             {
                 headers: {
                     "Accept": "application/json;odata=nometadata",
                     "odata-version": ""
                 }
             })
             .then((response: SPHttpClientResponse): Promise<{ value: IListItem[] }> => {
                 return response.json();
             })
             .then((json: { value: IListItem[] }) => {
                 console.log(JSON.stringify(json.value));
                 return items=json.value.map((v,i)=>(
                     {
                         // key: v.id,
                         id: v.Id,
                         title: v.Title,
                         created: v.Created,
                         createdby: v.Author.Title,
                         modified: v.Modified,
                         modifiedby: v.Editor.Title
                     }
                 ));
             });
         case "News":
             let newsitems: INewsListItem[];
             // tslint:disable-next-line:max-line-length
             return requester.get(`${siteUrl}/_api/web/lists/getbytitle('${listName}')/items?$select=Title,Id,Modified,Created,Created By,Modified By,newsheader,newsbody,expiryDate`,
             SPHttpClient.configurations.v1,
             {
                 headers: {
                     "Accept": "application/json;odata=nometadata",
                     "odata-version": ""
                 }
             })
             .then((response: SPHttpClientResponse): Promise<{ value: INewsListItem[] }> => {
                 return response.json();
             })
             .then((json: { value: INewsListItem[] }) => {
                 return newsitems=json.value.map((v,i)=>(
                     { 
                         id: v.Id,
                         title: v.Title,
                         created: v.Created,
                         createdby: v.Author.Title,
                         modified: v.Modified,
                         modifiedby: v.Editor.Title,
                         newsheader: v.newsheader,
                         newsbody: v.newsbody,
                         expiryDate: v.expiryDate
                     }
                 ));
             });
         case "Announcements":
             let announcementitems: IAnnouncementListItem[];
             return requester.get(`${siteUrl}/_api/web/lists/getbytitle('${listName}')/items?$select=Title,Id,Created,Author/Title,Modified,Editor/Title,announcementBody,expiryDate&$expand=Author,Editor`,
             SPHttpClient.configurations.v1,
             {
                 headers: {
                     "Accept": "application/json;odata=nometadata",
                     "odata-version": ""
                 }
             })
             .then((response: SPHttpClientResponse): Promise<{ value: IAnnouncementListItem[] }> => {
                 return response.json();
             })
             .then((json: { value: IAnnouncementListItem[] }) => {
                 return announcementitems=json.value.map((v,i)=>(
                     { 
                         id: v.Id,
                         title: v.Title,
                         created: v.Created,
                         createdby: v.Author.Title,
                         modified: v.Modified,
                         modifiedby: v.Editor.Title,
                         announcementBody: v.announcementBody,
                         expiryDate: v.expiryDate
                     }
                 ));
             });
         case "Directory":
             let directoryitems: IDirectoryListItem[];
             return requester.get(`${siteUrl}/_api/web/lists/getbytitle('${listName}')/items?$select=Title,Id`,
             SPHttpClient.configurations.v1,
             {
                 headers: {
                     "Accept": "application/json;odata=nometadata",
                     "odata-version": ""
                 }
             })
             .then((response: SPHttpClientResponse): Promise<{ value: IDirectoryListItem[] }> => {
                 return response.json();
             })
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的@microsoft/sp-http.SPHttpClient.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。