本文整理汇总了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;
}
示例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;
}
示例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);
}
);
});
示例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;
}
示例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); });
});
示例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;
}
示例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));
}
}
示例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);
}
);
});
示例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;
}