有没有办法使用JavaScript客户端对象模型编辑多值查找字段? 我需要删除一个或多个查找值,最后添加一个或多个值。
我到处搜索,我阅读了MSDN文档,...,我也在我的桌子下看看!
感谢。
答案 0 :(得分:6)
Multiple-Column Lookup
值表示为SP.FieldLookupValue个对象的数组。
Lookup
字段值var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle(listTitle);
var listItem = list.getItemById(1);
context.load(listItem);
context.executeQueryAsync(
function() {
var lookupVals = listItem.get_item(fieldName); //get multi lookup value (SP.FieldLookupValue[])
for(var i = 0;i < lookupVals.length;i++) {
console.log(lookupVals[i].get_lookupId()); //print Id
console.log(lookupVals[i].get_lookupValue()); //print Value
}
},
function(sender,args){
console.log(args.get_message());
}
);
Lookup
字段值要更新多个Lookup值,您需要指定类型SP.FieldLookupValue[]
的值。请注意,SP.FieldLookupValue
只能通过指定LookupId
进行初始化。
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle(listTitle);
var listItem = list.getItemById(1);
var lookupVals = [];
//set 1st Lookup value
var lookupVal1 = new SP.FieldLookupValue();
lookupVal1.set_lookupId(1);
lookupVals.push(lookupVal1);
//set 2nd Lookup value
var lookupVal2 = new SP.FieldLookupValue();
lookupVal2.set_lookupId(2);
lookupVals.push(lookupVal2);
listItem.set_item(fieldName,lookupVals);
listItem.update();
context.executeQueryAsync(
function() {
console.log('Multi lookup field has been updated');
},
function(sender,args){
console.log(args.get_message());
}
);
答案 1 :(得分:0)
您可以通过js获取查找值:
clientContext.executeQueryAsync(function(){
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
chartX.push(oListItem.get_item(xAxisName));
}
lookupValue1= chartX["0"].$1g_1;
lookupValue2= chartX["1"].$1g_1;