zoukankan      html  css  js  c++  java
  • [SharePoint]javascript client object model 获取lookup 类型的field的值,包括user类型(单人或者多人)的值。how to get the multiple user type/lookup type field value by Javascript client object model

    1. how to get value

     1 var context = new SP.ClientContext.get_current();
     2 var web = context.get_web();
     3 var list = web.get_lists().getByTitle(listTitle);
     4 var listItem = list.getItemById(1);   
     5 context.load(listItem);
     6 context.executeQueryAsync(
     7    function() {
     8        var lookupVals = listItem.get_item(fieldName); //get multi lookup value (SP.FieldLookupValue[])
     9        for(var i = 0;i < lookupVals.length;i++) {
    10            console.log(lookupVals[i].get_lookupId()); //print Id
    11            console.log(lookupVals[i].get_lookupValue()); //print Value
    12        }
    13    },
    14    function(sender,args){
    15        console.log(args.get_message());
    16    }
    17 );

    2. how to update value

     1 var context = new SP.ClientContext.get_current();
     2 var web = context.get_web();
     3 var list = web.get_lists().getByTitle(listTitle);
     4 var listItem = list.getItemById(1);   
     5 
     6 var lookupVals = [];
     7 //set 1st Lookup value
     8 var lookupVal1 = new SP.FieldLookupValue();
     9 lookupVal1.set_lookupId(1);
    10 lookupVals.push(lookupVal1);
    11 //set 2nd Lookup value
    12 var lookupVal2 = new SP.FieldLookupValue();
    13 lookupVal2.set_lookupId(2);
    14 lookupVals.push(lookupVal2);
    15 
    16 listItem.set_item(fieldName,lookupVals);
    17 listItem.update();
    18 
    19 context.executeQueryAsync(
    20    function() {
    21         console.log('Multi lookup field has been updated');
    22    },
    23    function(sender,args){
    24        console.log(args.get_message());
    25    }
    26 );
  • 相关阅读:
    数组循环三种方式
    PHP上传RAR压缩包并解压目录
    把session写到数据库中
    PHP错误处理方式
    PHP异常处理机制
    css文字的强制换行和超出宽度省略变成点儿
    Mybatis之@Provider的使用方式
    rsync+ssh 枯木
    RHEL6下squid代理之正向代理 枯木
    MySQL体系结构 枯木
  • 原文地址:https://www.cnblogs.com/cwyang/p/5643561.html
Copyright © 2011-2022 走看看