我需要做这样的事情。 下面的图片有3个条款,我需要在我的第1学期下移动我的第3学期(然后我的学期3将作为我的学期1的子学期。
我如何使用JSOM,2013 Sharepoint实现这一目标。在这里,我使用了用于重用术语的代码,但重用仅仅意味着共享。我虽然重复使用这个术语并在以后删除它,但它确实删除了两个。我只需要移动,任何想法? MSDN没有为moveTerm提供方法..
function reuseTerm() {
alert('check reuse');
var sourceTermId = 'c0351a3d-5eec-454d-8bc6-4f3ac0992a84'; //Id of source Term
var destTermId = '2085753f-2804-44c4-b16d-5b93cbbc989d'; //Id of Term below which a reused term will be created
var ctx = SP.ClientContext.get_current();
var taxonomySession = SP.Taxonomy.TaxonomySession.getTaxonomySession(ctx);
var sourceTerm = taxonomySession.getTerm(sourceTermId);
var destTerm = taxonomySession.getTerm(destTermId);
destTerm.reuseTerm(sourceTerm, true);//I need something like destTerm.moveTerm(sourceTerm, true);
ctx.executeQueryAsync(
function () {
alert('Reused term has been created');
},
function (sender, args) {
alert(args.get_message());
});
}
答案 0 :(得分:1)
使用SP.Taxonomy.Term.move Method将当前Term对象移动为其他术语的子级。
示例强>
function moveTerm(sourceTermId,targetTermId,success,error)
{
var ctx = SP.ClientContext.get_current();
var ts = SP.Taxonomy.TaxonomySession.getTaxonomySession(ctx);
var termStore = ts.getDefaultSiteCollectionTermStore();
var sourceTerm = termStore.getTerm(sourceTermId);
var targetTerm = termStore.getTerm(targetTermId);
sourceTerm.move(targetTerm);
ctx.executeQueryAsync(success,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 sourceTermId = 'source-term-guid';
var targetTermId = 'target-term-guid';
moveTerm(sourceTermId,targetTermId,
function(){
console.log(String.format('Term {0} has been moved under Term {0}',sourceTermId,targetTermId));
},
function(sender,args){
console.log(args.get_message());
});
});