0

如何使用 SPservices 将多个用户添加到具有多个用户的 Item?可以在 JQuery 中使用吗?

我有下一个jQuery:

//Users ID, who shoud be located in the field "Users"
var us1 = 110; 
var us2 = 113;
var uw3 = 115;


$().SPServices({
        operation: "UpdateListItems",
        async: false,
        batchCmd: "Update",
        listName: "testList",
        valuepairs: [["users", us1]],
        ID: 5, 
        completefunc: function(xData, Status) {
             alert("yeah, ready!");
    });
}

现在字段 ["users"] 的类型为 "Multiple Users",并且此方法仅添加一个用户 (us1)。那么,如何向字段 ["users"] 添加多个用户(us1、us2、us3)?

4

1 回答 1

1

我知道这个问题已经有一年了,但我找到了它并且没有答案,所以:用于更新用户字段与多个选择(添加和删除用户)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js">

function UpdateParticipants(listName, itemId, userName, userId, initialData) {

    var usersToSet = "";
    if (!IsStringEmpty(initialData)) {
        usersToSet = initialData + ";#" + userId + ";#" + userName;
    } else {
        usersToSet = userId + ";#" + userName;
    }

    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        debug: true,
        listName: listName,
        ID: itemId,
        valuepairs: [["EventParticipants", usersToSet]],
        completefunc: function (xData, Status) {
            if (Status != "success") {
                alert("Something Went Wrong. You haven't applied for the event, please contact Event Manager.");
            } else {
                alert("You have succesfully applied for the event.");
            }
        }
    });

}

function RemoveParticipant(listName, itemId, userName, userId, initialData) {

    var usersToDelete = userId + ";#" + userName;
    var usersToSet = initialData.replace(usersToDelete, "");

    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        debug: true,
        listName: listName,
        ID: itemId,
        valuepairs: [["EventParticipants", usersToSet]],
        completefunc: function (xData, Status) {
            if (Status != "success") {
                alert("Something Went Wrong. You haven't resigned from the event, please contact Event Manager.");
            } else {
                alert("You have succesfully resigned from the event.");
            }
        }
    });

}

function IsStringEmpty(inputString) {
    if (inputString != null && inputString != "" && inputString != "undefined" && inputString.length > 0) {
        return false;
    }
    return true;
}

  
</script>

listName - 实际上是在我的情况下列出 GUID ... :)

于 2015-04-30T10:44:18.537 回答