首页 > 代码库 > sharepoint ECMA 添加指定的人员和指定的角色到某个list里

sharepoint ECMA 添加指定的人员和指定的角色到某个list里

有的时候我们需要给某个list添加指定的人员和指定的角色:具体代码如下:

 1         function AddUserAndRoleToList() {
 2             var SubClientContent =new SP.ClientContext(siteUrl);
 3             var SubWeb = SubClientContent.get_web();
 4             var subList = SubWeb.get_lists().getByTitle(self.DocumentName());
 5             $("div[id$=‘DPUser_upLevelDiv‘] div").each(function (i, value) {
 6                 if (value.id != null) {
 7                     if (value.id == ‘divEntityData‘ && value.parentElement.title != null) {
 8                         var ouser = value.parentElement.title;
 9                         //break role inheritance
10                         subList.breakRoleInheritance(false, true);
11                         var currentUser = SubWeb.ensureUser(ouser);
12                         var roleDefinition = SP.RoleDefinitionBindingCollection.newObject(SubClientContent);
13                         roleDefinition.add(SubWeb.get_roleDefinitions().getByType(SP.RoleType.contributor));
14                         subList.get_roleAssignments().add(currentUser, roleDefinition);
15                         SubClientContent.executeQueryAsync(
16                                         Function.createDelegate(this, onQuerySucceeded),
17                                         Function.createDelegate(this, onQueryFailed)
18                             );
19                     }
20                 }
21             });
22 
23         }//add list success