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 );
  • 相关阅读:
    BUPT复试专题—最小距离查询(2013)
    BUPT复试专题—中序遍历序列(2013)
    BUPT复试专题—统计节点个数(2013)
    BUPT复试专题—日期(2013)
    BUPT复试专题—内存分配(2014-2)
    BUPT复试专题—图像识别(2014-2)
    Catch That Cow(BFS)
    Pet(hdu 4707 BFS)
    Knight Moves(BFS,走’日‘字)
    Lost Cows(BIT poj2182)
  • 原文地址:https://www.cnblogs.com/cwyang/p/5643561.html
Copyright © 2011-2022 走看看