Mar*_*rco 3 javascript sharepoint
有没有办法使用JavaScript客户端对象模型编辑多值查找字段?我需要删除一个或多个查找值,最后添加一个或多个值.
我到处搜索,我阅读MSDN文档,...,我也看看我的桌子下面!
谢谢.
Multiple-Column Lookupvalue表示为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());
}
);
Run Code Online (Sandbox Code Playgroud)
Lookup字段值要更新多个Lookup值,您需要指定type的值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());
}
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18366 次 |
| 最近记录: |