SharePoint 2010 Client Object Model + set the value of a multiple lookup field with Javascript

六眼飞鱼酱① 提交于 2019-12-13 06:16:25

问题


I'm trying to update a list item with the SharePoint 2010 Client Object Model and Javascript. The item I am trying to update has a Multiple Value Lookup field. I can successfully set this field, but only with one value. Does anyone know how to set it with multiple values?

var _newLookupField = new SP.FieldLookupValue();
    _newLookupField.set_lookupId(itemArray.toString()); //this works if array is only 1 item        

    currentItem.set_item('Lookup_x0020_Field', _newLookupField);

回答1:


var lookupsIds = [1,2,4];
var lookups = [];
for (var ii in lookupsIds) {
    var lookupValue = new SP.FieldLookupValue();
    lookupValue.set_lookupId(lookupsIds[ii]);
    lookups.push(lookupValue);
}
currentItem.set_item('Lookup_x0020_Field', lookups);
currentItem.update();



回答2:


I have created a blog post that clearly explain how to add a list item that contains metadata with lookup fields.

http://vangalvenkat.blogspot.com/2011/10/adding-new-document-item-whose-metadata.html



来源:https://stackoverflow.com/questions/7043316/sharepoint-2010-client-object-model-set-the-value-of-a-multiple-lookup-field-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!