【问题标题】:Sharepoint - Java Script - Get value from people picker column in a listSharepoint - Javascript - 从列表中的人员选择器列中获取值
【发布时间】:2014-07-03 16:59:51
【问题描述】:

我的 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,使用开发人员工具。 这是正确的方法吗? 还有其他更好的方法吗? 请建议一些文章,关于此的信息链接,因为我对共享点和客户端对象模型非常陌生。 提前致谢。

【问题讨论】:

  • 大家好,我看不到此查询的响应。请分享您的想法,想法请帮助我。谢谢。

标签: javascript sharepoint-2013 sharepoint-clientobject peoplepicker


【解决方案1】:
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));
            }
    });
}

【讨论】:

    【解决方案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 并面临类似问题的人有所帮助。

    谢谢!

    【讨论】:

    • 考虑到链接死了,完整的答案应该在你的答案中解释
    猜你喜欢
    • 2011-08-18
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 2022-11-24
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多