gpt4 book ai didi

javascript - 按术语名称获取 GUID - jsom

转载 作者:行者123 更新时间:2023-12-01 05:43:44 28 4
gpt4 key购买 nike

我需要将术语名称作为参数传递,并返回 SharePoint 2013、JSOM 中该特定术语的 GUID

例如,如果我传递“My Term 1”,它应该返回“My Term 1”相应的 GUID。

enter image description here

var termGuid=getTermByName('My Term 1');

function getTermByName(TermName){
return term.get_id();
}

最佳答案

SP.Taxonomy.TermStore.getTerms Method可用于查找TermTermStore .

以下示例演示如何查找 Term通过使用 JSOM 的标签:

function findTermsByLabel(label,success,error)
{
var ctx = SP.ClientContext.get_current();
var ts = SP.Taxonomy.TaxonomySession.getTaxonomySession(ctx);
var matchInfo = new SP.Taxonomy.LabelMatchInformation(ctx);
matchInfo.set_termLabel(label);
matchInfo.set_trimUnavailable(true);
var termMatches = ts.getTerms(matchInfo);
ctx.load(termMatches);
ctx.executeQueryAsync(
function(){
var terms = termMatches.get_data();
success(terms);
},
error);
}

使用

SP.SOD.registerSod('SP.ClientContext', SP.Utilities.Utility.getLayoutsPageUrl('sp.js'));
SP.SOD.registerSod('SP.Taxonomy.TaxonomySession', SP.Utilities.Utility.getLayoutsPageUrl('sp.taxonomy.js'));
SP.SOD.loadMultiple(['SP.ClientContext', 'SP.Taxonomy.TaxonomySession'], function(){

var termLabel = '--term label goes here--';

findTermsByLabel(termLabel,
function(terms){
if(terms.length == 0)
console.log('Term has not been found');
else if(terms.length > 1)
console.log(String.format("Several Terms exist with '{0}' label",termLabel));
else {
console.log(String.format('Term has been found: {0}'),terms[0].get_id().toString());
}
},
function(sender,args){
console.log(args.get_message());
});

});

关于javascript - 按术语名称获取 GUID - jsom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29025722/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com