解析角色创建错误

时间:2017-09-22 10:13:00

标签: javascript parse-server

当我执行以下代码时,遇到以下错误。 解析JavaScript版本:1.9.2

"TypeError: role must be a ParseRole or a String
    at e.value (https://unpkg.com/parse@1.10.0/dist/parse.min.js:13:26051)
    at ensureRoles (saceqihafu.js:48:14)
    at saceqihafu.js:70:1
    at https://static.jsbin.com/js/prod/runner-4.0.4.min.js:1:13850
    at https://static.jsbin.com/js/prod/runner-4.0.4.min.js:1:10792"


function ensureRoles() {
      console.log('Start')

     //create admin role
      var msgACL = new Parse.ACL();
      msgACL.setPublicReadAccess(false);
      msgACL.setPublicWriteAccess(false);
      var msgRole = new Parse.Role("merchant", msgACL);
      //msgRole.save().then(function(e) { console.log("msgRole role saved")}, function(err){console.log(err); });

      //create user role
      var developerRoleACL = new Parse.ACL();
      developerRoleACL.setPublicReadAccess(false);
      developerRoleACL.setPublicWriteAccess(false);
      var developerRole = new Parse.Role("developer", developerRoleACL);
      //developerRole.save().then(function(e) { console.log("developer role saved")}, function(err){console.log(err); });

      var SysAnalystACL = new Parse.ACL();
      SysAnalystACL.setPublicReadAccess(false);
      SysAnalystACL.setPublicWriteAccess(false);
      var SysAnalystRole = new Parse.Role("SysAnalyst", SysAnalystACL);
      //SysAnalystRole.save().then(function(e) { console.log("SysAnalyst role saved")}, function(err){console.log(err); });

      var memACL = new Parse.ACL();
      memACL.setPublicReadAccess(false);
      memACL.setPublicWriteAccess(false);
      memACL.setRoleWriteAccess(false);
      var memRole = new Parse.Role("member_merchant", memACL);
      //memRole.save().then(function(e) { console.log("memRole role saved")}, function(err){console.log(err); });

     console.log("saved")
     return Parse.Promise.when(
                          msgRole.save(null,{useMasterKey:true}), 
                          developerRole.save(null,{useMasterKey:true}),
                          SysAnalystRole.save(null,{useMasterKey:true}),
                          memRole.save(null,{useMasterKey:true})
      );

}

function Donefunction() {
    console.log('Done 1')
}

ensureRoles()
    .then(Donefunction)

如果我评论以下一行,

// memRole.save(NULL,{useMasterKey:真})

代码执行成功。 否则我得到上述错误。不确定什么是错的。解析角色中是否不允许使用下划线_

1 个答案:

答案 0 :(得分:0)

好的,弄明白了这个问题。

Line#memACL.setRoleWriteAccess(false);

应指定角色名称,它才能正常工作。

memACL.setRoleWriteAccess("testRole",false);

错误描述很差。