如何使用Javascript客户端对象模型检索Sharepoint 2010列表项权限

时间:2015-04-08 15:02:43

标签: javascript sharepoint sharepoint-2010 csom

我在Sharepoint中检查列表项权限的功能似乎不起作用。它被放置在Sharepoint 2010站点上的aspx文件中。我在尝试运行它时收到以下错误消息。有谁知道应该怎么做?我在C#中找到了相同功能的大量示例,但无法在Javascript中找到任何内容。谢谢!

function checkPermissions(){
var ctx = new SP.ClientContext.get_current();
var oBooksList=ctx.get_web().get_lists().getByTitle('test Repository');
var listItem=oBooksList.getItemById(2);


//ctx.load(listItem.get_roleAssignments());
ctx.load(listItem, 'RoleAssignments');
ctx.executeQueryAsync(
    Function.createDelegate(this, this.onSucceededCallback),
    Function.createDelegate(this, this.onFailedCallback));

}
function onSucceededCallback(sender, args){
    alert('it worked');
}

错误讯息:

SCRIPT5007: Unable to get value of the property 'apply': object is null or undefined 

1 个答案:

答案 0 :(得分:2)

这样的事情应该有所帮助......

<强> UNTESTED

function checkPermissions(){
    var ctx = new SP.ClientContext.get_current();
    var oBooksList = ctx.get_web().get_lists().getByTitle('test Repository');
    var listItem = oBooksList.getItemById(2);
    var roles = listItem.get_roleAssignments();

    ctx.load(roles);
    ctx.executeQueryAsync(
        // success
        function (sender, args){
            var roleInfo = '';
            var roleEnumerator = roles.getEnumerator();
            // enumerate the roles
            while (roleEnumerator.moveNext()) {
                var role = roleEnumerator.get_current();
                var principal = role.get_member();
                // get the principal
                ctx.load(principal);
                ctx.executeQueryAsync(
                    // success
                    function (sender, args){
                        // alert the title
                        alert(principal.get_title());
                    }, 
                    // failure
                    function (sender, args){
                        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
                    });
            }
        }, 
        // failure
        function (sender, args){
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
        });

}