2014-11-06 31 views

回答

1

最简单的方法是使用云代码。下面是你如何做到这一点:

Parse.Cloud.beforeSave("YourObject", function(request, response) 
{ 
    // Find a way to decide if writing is allowed. 
    var writingForbidden = (request.master === false); 

    if (writingForbidden) 
    { 
     var readOnlyProperties = ["property1", "property2", "property3", "..."]; 

     var dirtyProperties = request.object.dirtyKeys(); 
     for (i = 0 ; i < dirtyProperties.length ; i++) { 
      var dirtyProperty = dirtyProperties[i]; 
      if (readOnlyProperties.indexOf(dirtyProperty) > -1) { 
       return response.error("Trying to change a readonly property : " + dirtyProperty); 
      } 
     } 
    } 

    return response.success(); 
}