我正在尝试保存记录然后获取新创建的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。 我做错了什么?提前谢谢。
答案 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")
});