gpt4 book ai didi

javascript - Sharepoint 2013。使用 JavaScript 的多值查找字段

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:47:52 25 4
gpt4 key购买 nike

有没有办法使用 JavaScript 客户端对象模型编辑多值查找字段?我需要删除一个或多个查找值,并最终添加一个或多个值。

我到处搜索,我阅读 MSDN 文档,...,我也在我的办公 table 底下看一看!

谢谢。

最佳答案

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字段值

要更新多个查找值,您需要指定 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());
}
);

关于javascript - Sharepoint 2013。使用 JavaScript 的多值查找字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22694749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com