Parse.com:无法在解析javascript中获得最近创建的objectid

时间:2015-02-19 06:48:30

标签: javascript parse-platform facebook-javascript-sdk

我正在尝试保存记录然后获取新创建的objectId。我正在使用以下代码。

     var query = new Parse.Query("Inspection");
     var Inspection = new Parse.Object("Inspection"); 
        query.include('property');
        query.equalTo("property", { "__type": "Pointer", "className": "Property",  "objectId": propertyId});
        query.first({
          success: function(inspectionData) {

    Inspection.set("companyAddress", inspectionData.get("companyAddress"));
    Inspection.set("companyLogo", inspectionData.get("companyLogo"));
    Inspection.set("tenantPhone", inspectionData.get("tenantPhone"));
    Inspection.save().then(function(Inspection) {
         console.log("in success");
         console.log(Inspection);
         console.log(Inspection.id);
    },
    function(error) {
         console.log("Error: " + error.code + " " + error.message);
    });
},
          error: function(error) {
            console.log('in error')
             console.log("Error: " + error.code + " " + error.message);
           }
         });

但插入了新记录,我没有得到"成功的console.log"和对象ID。 我做错了什么?提前谢谢。

1 个答案:

答案 0 :(得分:0)

创建像这样的新对象的正确语法不是吗?

var InspectionClass = Parse.Object.extend("Inspection");
var Inspection = new InspectionClass();

甚至更好,使用Backbone Syntax:

var inspection = Parse.Object.extend({
    className: "Inspection",
    companyAddress: inspectionData.get("companyAddress"),
    companyLogo: inspectionData.get("companyLogo"),
    tenantPhone: inspectionData.get("tenantPhone")
});