简体   繁体   English

Parse.com beforeSave获取脏值

[英]Parse.com beforeSave get dirty values

On the parse.com info log are the keys and values of the update visible: 在parse.com信息日志上,可见更新的键和值: parse.com信息日志 This is valid JSON, see 这是有效的JSON,请参阅

{
    "original": {
        "countReplies": 0,
        "owner": {
            "__type": "Pointer",
            "className": "_User",
            "objectId": "OKjocXCfUR"
        },
        "rating": 0,
        "message": "affdgf",
        "objectId": "7Rdu6ZWugr",
        "createdAt": "2015-02-03T11:57:06.523Z",
        "updatedAt": "2015-02-03T11:57:06.523Z"
    },
    "update": {
        "rating": -1
    }
}

How can I access the "update" object from the request in beforeSave? 如何从beforeSave中的请求访问“更新”对象? Here are some attempts without success: 这是一些没有成功的尝试:

console.log("1. update: " + request.object.dirtyKeys());
console.log("2. original: " + JSON.stringify(request.object));
console.log("3. rating original: " + request.object.get("rating"));
console.log("4. isDirty: " + request.get("update"));
console.log("5. " + request.object.get("update"));
console.log("6. " + update.get("rating"));
console.log("7. " + request.get("Input"));

Update is neither a property of request.object or dirtyKeys() , it is simply the JSON being passed to the server. Update既不是request.object的属性,也不是dirtyKeys()的属性,它只是传递给服务器的JSON。 By the time you have reached function level it has already been interpreted by the SDK . 在您达到功能级别时, SDK已经对其进行了解释。

Array of string dirtyKeys( ) Returns an array of keys that have been modified since last save/refresh 字符串数组dirtyKeys()返回自上次保存/刷新以来已修改的键的数组

Returns: Array of string 返回:字符串数组

Your request object IS the updated version of the object. 您的请求对象该对象的更新版本。 This is what the SDK is comparing to the database to determine which keys are dirty. 这就是SDK与数据库进行比较,以确定哪些键是脏键。

So, your updates are simply in the request.object 因此,您的更新仅在request.object

request.object.get("rating");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM