问题
I am trying to use the javascript object model to retrieve a list of users/groups for a list and their permissions at the list level. So far I have this which returns a member object but I cant get any information about the member. When I try to use rAssignment.get_member().get_id(), or rAssignment.get_member().get_title() I get an error.
//Get List Permissions
function getListPerms() {
var clientContext = new SP.ClientContext();
var siteColl = clientContext.get_site();
var site = clientContext.get_web();
listSecurableObject = site.get_lists().getByTitle($("[name='ListSlct']").val());
listRoleAssignments = listSecurableObject.get_roleAssignments();
clientContext.load(listRoleAssignments);
clientContext.executeQueryAsync(Function.createDelegate(this, this.getListPerms_onQuerySucceeded),Function.createDelegate(this, this.getListPerms_onQueryFailed));
}
function getListPerms_onQuerySucceeded() {
var listPerms="";
listPerms += '<table border="1">';
listPerms += '<tr>';
listPerms += '<td align="center">ID</td>';
listPerms += '</tr>';
var listPermsEnumerator = this.listRoleAssignments.getEnumerator();
while (listPermsEnumerator.moveNext()) {
var rAssignment = listPermsEnumerator.get_current();
listPerms += '<tr>';
listPerms += '<td align="center">' + rAssignment.get_member() + '</td>';
listPerms += '</tr>';
}
listPerms += '</table>';
document.getElementById('listPermsTable').innerHTML = listPerms;
}
function getListPerms_onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
回答1:
Try changing your clientContext.load() function call as follows:
clientContext.load(listSecurableObject, 'Include(RoleAssignments, RoleAssignments.Include(Member))');
Now in the getListPerms_onSucceeded() method you ought to be able to enumerate through listSecurableObject.get_roleAssignments() and get the members similar to how you're already doing it (although you'll probably want to use rAssignment.get_member().get_loginName() ).
来源:https://stackoverflow.com/questions/15935101/get-user-group-permissions-for-list-using-javascriptecmascript