當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Text.format方法代碼示例

本文整理匯總了TypeScript中@microsoft/sp-core-library.Text.format方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Text.format方法的具體用法?TypeScript Text.format怎麽用?TypeScript Text.format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@microsoft/sp-core-library.Text的用法示例。


在下文中一共展示了Text.format方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getErrorMessage

    /**
     * Returns an error message based on the specified error object
     * @param error : An error string/object
     */
    private getErrorMessage( webUrl: string, error: any ): string {
        let errorMessage: string = error.statusText ? error.statusText : error.statusMessage ? error.statusMessage : error;
        const serverUrl = `{window.location.protocol}//{window.location.hostname}`;
        const webServerRelativeUrl = webUrl.replace(serverUrl, '');

        if (error.status === 403) {
            errorMessage = Text.format(strings.ErrorWebAccessDenied, webServerRelativeUrl);
        } else if (error.status === 404) {
            errorMessage = Text.format(strings.ErrorWebNotFound, webServerRelativeUrl);
        }
        return errorMessage;
    }
開發者ID:,項目名稱:,代碼行數:16,代碼來源:

示例2: generateFilters

    /*************************************************************************************************
     * Generates the CAML filters based on the specified array of IQueryFilter objects
     * @param filters : The filters that needs to be converted to a CAML string
     *************************************************************************************************/
    private static generateFilters(filters:IQueryFilter[]): string {
        
        // Store the generic filter format for later use
        let query = '';
        let filterXml = '';

        // Appends a CAML node for each filter
        let itemCount = 0;

        for(let filter of filters.reverse()) {
            filterXml = '<{0}><FieldRef Name="{1}" /><Value {2} Type="{3}">{4}</Value></{0}>';
            itemCount++;
            let specialAttribute = '';

            // Sets the special attribute if needed
            if(filter.field.type == QueryFilterFieldType.Datetime) {
                specialAttribute = 'IncludeTimeValue="' + filter.includeTime + '"';
            }

            // If it's a <IsNull /> or <IsNotNull> filter
            if(filter.operator == QueryFilterOperator.IsNull || filter.operator == QueryFilterOperator.IsNotNull) {
                filterXml = '<{0}><FieldRef Name="{1}" /></{0}>';
                query += Text.format(filterXml, QueryFilterOperator[filter.operator], filter.field.internalName);
            }

            // If it's a taxonomy filter
            else if (filter.field.type == QueryFilterFieldType.Taxonomy) {
                query += this.generateTaxonomyFilter(filter);
            }

            // If it's a user filter
            else if (filter.field.type == QueryFilterFieldType.User) {
                query += this.generateUserFilter(filter);
            }

            // If it's any other kind of filter (Text, DateTime, Lookup, Number etc...)
            else {
                let valueType = (filter.field.type == QueryFilterFieldType.Lookup ? QueryFilterFieldType[QueryFilterFieldType.Text] : QueryFilterFieldType[filter.field.type]);
                query += Text.format(filterXml, QueryFilterOperator[filter.operator], filter.field.internalName, specialAttribute, valueType, this.formatFilterValue(filter));
            }

            // Appends the Join tags if needed
            if (itemCount >= 2) {
                let logicalJoin = QueryFilterJoin[filter.join];
                query = Text.format("<{0}>", logicalJoin) + query;
                query += Text.format("</{0}>", logicalJoin);
            }
        }
        
        return query;
    }
開發者ID:,項目名稱:,代碼行數:55,代碼來源:

示例3:

		return new Promise<any>((resolve,reject) => {
			let endpoint = Text.format("{0}/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser", webUrl);
			let data:any = {
                queryParams:{
                    __metadata:{
                        'type':'SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters'
                    },
					QueryString: query,
                    PrincipalSource: principalSource,
					PrincipalType: principalType,
					MaximumEntitySuggestions: maximumEntitySuggestion || 50
                }
            };
			let options: ISPHttpClientOptions = { headers: { 'odata-version': '3.0' }, body: JSON.stringify(data) };

			this.spHttpClient.post(endpoint, SPHttpClient.configurations.v1, options)
				.then((response: SPHttpClientResponse) => {
					if(response.ok) {
						resolve(response.json());
					}
					else {
						reject(response.statusText);
					}
				})
				.catch((error) => {
					reject(error);
				}
			); 
        });
開發者ID:,項目名稱:,代碼行數:29,代碼來源:

示例4: generateTaxonomyFilter

    /*************************************************************************************************
	 * Generates a valid CAML filter string based on the specified taxonomy filter
	 * @param filter : The taxonomy filter that needs to be formatted into a CAML filter string
	 *************************************************************************************************/
    private static generateTaxonomyFilter(filter:IQueryFilter): string
    {
        let filterOutput = '';
        let filterTerms = filter.value as ITag[];

        if(isEmpty(filter.value)) {
            return '';
        }
        else if (filter.operator == QueryFilterOperator.ContainsAny || filterTerms == null) {
            let values = filterTerms != null ? filterTerms.map(x => Text.format("<Value Type='Integer'>{0}</Value>", x.key)).join('') : '';
            filterOutput = Text.format("<In><FieldRef Name='{0}' LookupId='TRUE' /><Values>{1}</Values></In>", filter.field.internalName, values);
        }
        else if (filter.operator == QueryFilterOperator.ContainsAll) {
            let taxFilters: IQueryFilter[] = [];

            for(let term of filterTerms) {
                let termValue:ITag[] = [ term ];

                let taxFilter:IQueryFilter = {
                    index: null,
                    field: filter.field,
                    value: termValue,
                    join: QueryFilterJoin.And,
                    operator: QueryFilterOperator.ContainsAny
                };
                taxFilters.push(taxFilter);
            }

            filterOutput = this.generateFilters(taxFilters);
        }

        return filterOutput;
    }
開發者ID:,項目名稱:,代碼行數:37,代碼來源:

示例5: 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,代碼來源:

示例6: ensureSearchQueryParameter

	/**************************************************************************************************
	 * Recursively executes the specified search query using batches of 500 results until all results are fetched
	 * @param queryParameters : The search query parameters following the "/_api/search/query?" part
	 * @param parameterName : The name of the parameter that needs to be ensured
	 * @param parameterValue : The value of the parameter that needs to be ensured
	 **************************************************************************************************/
	private ensureSearchQueryParameter(queryParameters: string, parameterName: string, parameterValue: any): string {
		if(parameterValue) {
			let strParameter = Text.format("{0}={1}", parameterName, parameterValue);
			queryParameters = queryParameters.replace(new RegExp('StartRow=\\d*', 'gi'), strParameter);

			if(queryParameters.toLowerCase().indexOf(parameterName) < 0) {
				queryParameters += ('&' + strParameter);
			}
		}
		return queryParameters;
	}
開發者ID:,項目名稱:,代碼行數:17,代碼來源:

示例7: getTenantPropertyValue

    /**
     * Get the value of a tenant property bag property
     * @param key the property bag key
     */
    public async getTenantPropertyValue(key: string): Promise<any> {
        // Get settings from tenant properties
        const url = Text.format("{0}/_api/web/GetStorageEntity('{1}')", this._context.pageContext.site.absoluteUrl, key);

        try {
            const response = await this._context.spHttpClient.get(url, SPHttpClient.configurations.v1);            
            const data = await response.json();
                
            if (response.ok) {
                return data.Value;
            } else {

                // Expected response for errors
                const errorDetails = data["ExceptionMessage"];
                throw(errorDetails);
            }

        } catch (error) {
            Logger.write(Text.format("[TenantDataProvider_getTenantProperty]: Error: {0}", error));
        }    
    }
開發者ID:AdrianDiaz81,項目名稱:sp-dev-fx-extensions,代碼行數:25,代碼來源:TenantDataProvider.ts

示例8: AND

		return new Promise<string[]>((resolve,reject) => {
			let queryProperties = Text.format("querytext='SPSiteUrl:{0} AND (contentclass:STS_Site OR contentclass:STS_Web)'&selectproperties='Path'&trimduplicates=false&rowLimit=500&Properties='EnableDynamicGroups:true'", siteUrl);

			this.getSearchResultsRecursive(siteUrl, queryProperties)
				.then((results: any) => {
					resolve(this.getPathsFromResults(results));
				})
				.catch((error) => {
					reject(error);
				}
			);
		});	
開發者ID:,項目名稱:,代碼行數:12,代碼來源:

示例9: generateUserFilter

    /*************************************************************************************************
	 * Generates a valid CAML filter string based on the specified user filter
	 * @param filter : The user filter that needs to be formatted into a CAML filter string
	 *************************************************************************************************/
    private static generateUserFilter(filter:IQueryFilter): string
    {
        let filterOutput = '';
        let filterUsers = filter.value as IPersonaProps[];

        if(filter.me) {
            filterOutput = Text.format("<Eq><FieldRef Name='{0}' /><Value Type='Integer'><UserID /></Value></Eq>", filter.field.internalName);
        }
        else if(isEmpty(filter.value)) {
            return '';
        }
        else if (filter.operator == QueryFilterOperator.ContainsAny || filterUsers == null)
        {
            let values = filterUsers != null ? filterUsers.map(x => Text.format("<Value Type='Integer'>{0}</Value>", x.optionalText)).join('') : '';
            filterOutput = Text.format("<In><FieldRef Name='{0}' LookupId='TRUE' /><Values>{1}</Values></In>", filter.field.internalName, values);
        }
        else if (filter.operator == QueryFilterOperator.ContainsAll)
        {
            let userFilters: IQueryFilter[] = [];

            for(let user of filterUsers) {
                let userValue:IPersonaProps[] = [ user ];

                let userFilter:IQueryFilter = {
                    index: null,
                    field: filter.field,
                    value: userValue,
                    join: QueryFilterJoin.And,
                    operator: QueryFilterOperator.ContainsAny
                };
                userFilters.push(userFilter);
            }

            filterOutput = this.generateFilters(userFilters);
        }

        return filterOutput;
    }
開發者ID:,項目名稱:,代碼行數:42,代碼來源:


注:本文中的@microsoft/sp-core-library.Text.format方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。