简体   繁体   English

如何通过JavaScript查询获取SharePoint多选字段的选定值

[英]How to get the selected value(s) of a SharePoint Multi-select field via JavaScript query

I have a page in SharePoint that builds a bunch of tables using JavaScript. 我在SharePoint中有一个页面,该页面使用JavaScript构建了一堆表。 I need to get the selected value of a multi-select field from a list and write that value to a column in a table. 我需要从列表中获取多选字段的选定值,并将该值写入表中的列。 I've got all the other values I need, but this one either throws an error or returns [Object Object] depending on how I write it. 我已经获得了我需要的所有其他值,但是这个值要么抛出错误,要么根据我的编写方式返回[Object Object]

fieldValue = listItemArray[i].get_item(listFieldArray[j].fieldInternalName);

returns [Object Object] and when I expand fieldValue in the watch list in my browser debugger, it returns only the first option in the list, not the selected value, but still writes [Object Object] to the page. 返回[Object Object] ,当我在浏览器调试器的监视列表中展开fieldValue时,它仅返回列表中的第一个选项,而不返回所选值,但仍将[Object Object]写入页面。

Here is the answer that worked: 这是有效的答案:

Custom Lookup Field 自定义查找字段

More specifically: 进一步来说:

                value = listItemArray[i].get_item(listFieldArray[j].fieldInternalName);
            for (var z=0; z<value.length; z++) {
            var valueLU=value[z];
            fieldValue=valueLU.get_lookupValue();
            }

multi select field returns the array of all the selected choices. multi select字段返回所有选定选项的数组。 So you will have to iterate this array to access all the objects present. 因此,您将必须迭代此数组以访问存在的所有对象。

again selected choices will be the object as Lookup field stores object (eg 5;#someValue) not the actual value. 再次选择的选项将是对象,因为“查找”字段存储对象(例如5; #someValue)而不是实际值。 IT has two properties IT有两个属性

lookup Id (5) 查找ID(5)

Lookup Value (someValue) 查找值(someValue)

Refer this link for more information - SharePoint JavaScript CSOM: Best way to deal with Lookup fields? 请参考此链接以获取更多信息-SharePoint JavaScript CSOM:处理查找字段的最佳方法?

Try below code. 尝试下面的代码。 It should work for you: 它应该为您工作:

objLength = oListItem.get_item('MultiLookup').length;

for(var i=0; i<objLength; i++){
    oListItem.get_item('MultiLookup')[i].get_lookupValue();
    //oListItem.get_item('MultiLookup')[i].get_lookupId();
}

Note : 注意 :

MultiLookup is the internal name of the multi select field. MultiLookup是多重选择字段的内部名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM