【问题标题】:How to add values to multiple lookup field in SharePoint using UpdateListItems如何使用 UpdateListItems 向 SharePoint 中的多个查找字段添加值
【发布时间】:2016-07-14 05:17:33
【问题描述】:

我需要使用 Sp-services 将多个值(另一个自定义列表的 ID 字段)添加到 Multiple Lookup 字段。
要使用的数据的正确格式是什么?
我已经尝试过( 5,9,6 ),但只选择了第一项。

【问题讨论】:

    标签: sharepoint office365 spservices


    【解决方案1】:

    我不太确定您为什么要这样做,因为您将添加这些项目 - 它们不能保存为值,因为列和查找列表之间存在关系,即如果您有查找列到 List1,然后从 List2 中添加一个 id 为 99 的新值并保存,它将保存对 List1 中 id 为 99 的列表项的引用。

    但如果有的话,有可能,这就是我附加多个查找选定值的方式:

        var lines = additionalTechnologies.split(';#');
    
        $.each(lines, function (index) {
            if (lines[index].length < 3) {
                $("select[title='Additional Technologies selected values']:first").append("<option value=" + lines[index] + " title=" + lines[index + 1] + ">" + lines[index + 1] + "</option>");
                $("select[title='Additional Technologies possible values'] option[value=" + lines[index] + "]").remove();
            }
        });
    

    并将它们从所有项目列表中删除。反之亦然。

    【讨论】:

    • 其实我需要在List2多个Lookup列中添加List1的ID字段值。我可以检索 List2 查找字段数据。但我不知道如何将多个值(多个 List1 ID 字段)添加到 Lookup 列?
    • 那么上面的代码正是你所需要的。
    • 但我需要更新 List2 中的那个字段
    • 好的。你需要在这里展示你的代码。你如何更新列表项?您希望从哪里运行代码?
    【解决方案2】:

    我找到了一种方法。

    // "list1Id" contains the array of LIST1 ID fields that you want to add...
    // "MULTIPLELOOKUPFIELD" is the multiple lookup field in the LIST2...
    
    var multipleLookupValue ="";
    for(i = 0; i < list1Id.length ; i++)
    {
        multipleLookupValue = multipleLookupValue + list1Id[i]+";#data;#";
    }
    
    var method = "UpdateListItems";
    
    $().SPServices({
        operation: method,
            async: false,  
            batchCmd: "New",
            listName: "LIST2" ,
            valuepairs: [["MULTIPLELOOKUPFIELD",multipleLookupValue]],
                completefunc: function (xData, Status) { 
    
                    //alert("Added new item to LIST2 list");                                            
                }
    
    });
    

    也许它会帮助某人......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多