我的应用程序读取 SharePoint 术语库,需要获取与用户语言关联的标签。我得到了用户的语言和 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",这是我需要到达的标签。