我的应用程序读取SharePoint Term Store并需要获取与用户语言相关联的标签。我得到了用户的语言和LCID,然后我在使用此代码的分类读取某个节点下的所有条款:阅读SharePoint分类术语存储和getDefaultLabel(lcid)
... some code to get the Term Store, then Term Group, then Term Set, and finally startTerm
var tsTerms = startTerm.get_terms();
context.load(tsTerms);
context.executeQueryAsync(
function() {
var termsEnum = tsTerms.getEnumerator();
while (termsEnum.moveNext()) {
var currentTerm = termsEnum.get_current();
var termName = currentTerm.get_name();
var userLabel = currentTerm.getDefaultLabel(lcid);
var userLabelValue = userLabel.get_value();
console.log ("Label=", userLabel, userLabelValue)
... more code ...
在while循环,我可以得到术语,我需要的所有属性,标签除外。在我在网上找到的其他示例中,为了获取默认标签,我的userLabel对象将被加载到上下文中,然后调用另一个context.executeQueryAsync。所有这一切都有道理,但这会导致对SharePoint服务器的大量调用。
但是,当我向控制台写入userLabel对象时,显示为SP.Result类型,当我打开它时,我在m_value下看到我想要的标签。所以应该不需要再次去服务器。但是,userLabelValue返回为0 - 显然,get_value()不起作用。在MSDN文档中,SP.Result对象类型仅供内部使用。有什么方法可以提取它存储的数据吗?
我附上了扩展对象的控制台图片,我们清楚地看到m_value =“Contrat”,这是我需要的标签。