0

我的 SharePoint 列表中有一个人员选取器列。

我需要从此列中获取所有值(名称)。我正在使用 Java 脚本代码从 SharePoint 列表中获取数据。

我的代码如下:

这里的“用户”是列表中列的名称。

var enumerator = listItem.getEnumerator();
while (enumerator.moveNext()) {

var _User = "";
if (colListItem.get_item(User) !== 'undefined' && colListItem.get_item(User) !== null) {
  //Check if people picker contains more than one value
                if (colListItem.get_item(User).length > 0) {
//Check if people picker contains only one value
                if (colListItem.get_item(User).length == 1) {
                    _User = colListItem.get_item(User)[0].$2e_1;
                }
//Check if people picker contains more than one value
                if (colListItem.get_item(User).length > 1) {
                for (var i = 0; i < colListItem.get_item(User).length; i++)
  {
  //Append all User names with a semi colon separator

               _User = _User + colListItem.get_item(User)[i].get_lookupValue() + ";";
                }
                        _User.trim;
                }
                }
            }
}
}

我知道我需要为此使用 get_lookupValue。但是,如果人员选择器列中有一个值,我会得到它,因为colListItem.get_item(User)[0].$2e_1; 我发现我需要$2e_1使用开发人员工具。这是正确的方法吗?还有其他更好的方法吗?请建议一些文章,关于此的信息链接,因为我对共享点和客户端对象模型非常陌生。提前致谢。

4

2 回答 2

0
function getListData(ListId) 
{
    $().SPServices(
    {
        operation: "GetListItems",
        async: false,
        listName: "NodueFormList",
        CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + ListId + "</Value></Eq></Where></Query>",
        completefunc: function (xData, Status) 
            {
                var SeparationCount = $(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount");
                if (SeparationCount > 0) 
                {
                    $(xData.responseXML).SPFilterNode("z:row").each(function () {
                        if ($(this).attr("ows_Admin") != undefined) { 
                            AdminId = $(this).attr("ows_Admin").split(';')[0];
                        }
                        if ($(this).attr("ows_HR") != undefined) { 
                           hrId = $(this).attr("ows_HR").split(';')[0];
                        }
                  });    
            }
        }
    });
}

function UpdateData(ListId)
{

    var adminaddtional = document.getElementById("txtareaAdition").value;
    siteUrl = "/sites/Empower/";
    var listName = "NodueFormList";
    var itemType = GetItemTypeFoListName(listName);
    var item = 
    {
        __metadata: { "type": itemType },
    };
    $.extend(item, { PendingwithId: hrId });
    //Multiple people picker update IsVisible is column name and Id add
    $.extend(item, { IsVisibleId:{'results':[AdminId,hrId]}}**);
    $.extend(item, { Flag: "0" });
    $.extend(item, { Additonalnotetoadmin: adminaddtional });
    $.extend(item, { Role: "HR" });
    $.extend(item, { IsActive: "Yes" });
    $.ajax(
    {
        url: siteUrl + "_api/Web/Lists/GetByTitle('" + listName + "')/GetItemById('" + ListId + "')",
        type: "POST",
        async: false,
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
        "accept": "application/json;odata=verbose",
        "Content-Type": "application/json;odata=verbose",
        "X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
        "IF-MATCH": "*",
        "X-Http-Method": "MERGE"
        },`enter code here`
        success: function (data) 
        {
            alert("Updated Successfully");

        },
        error: function (error) 
            {
                console.log(JSON.stringify(error));
            }
    });
}
于 2017-05-17T12:51:10.213 回答
-2

这里解释了一个明确的解决方案 -

http://gocodin.blogspot.in/2017/04/how-to-get-lookup-valueusername-from.html

我获得价值的方式_User = colListItem.get_item(User)[0].$2e_1; 是错误的。

可以使用 检索用户get_lookupvalue

希望这对所有刚接触sharepoint并面临类似问题的人有所帮助。

谢谢!

于 2017-04-12T09:54:21.520 回答