當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。