Sharepoint 2013.使用JavaScript的多值查找字段 [英] Sharepoint 2013. Multivalue lookup field with JavaScript

查看:89
本文介绍了Sharepoint 2013.使用JavaScript的多值查找字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way to edit a multivalue lookup field using the JavaScript Client Object Model? I need to remove one or more lookup values and, eventually, add one or more values.

我到处搜索,我读过MSDN文档,... ,我也看看我的桌子下面!

I search everywhere, I read MSDN documentation, ..., I also take a look under my desk!

谢谢。

推荐答案

多列查找值表示为 SP.FieldLookupValue 对象。

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 来初始化。

How to update multiple Lookup field value

For updating multiple Lookup value you need to specify value of type SP.FieldLookupValue[]. Note, SP.FieldLookupValue could be initialized by specifying LookupId only.

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());
   }
);

这篇关于Sharepoint 2013.使用JavaScript的多值查找字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆