ฉันกำลังสร้างแอปพลิเคชันสำหรับ Phonegap โดยใช้ Backbone Framework และ Parse.com เป็นบริการแบ็กเอนด์ ฉันสร้างวัตถุด้วย Parse.com (ตรงกับรุ่น Backbone) วัตถุนี้มีเมธอด saveDraftToP() ที่เรียกฟังก์ชัน Parse.com save() หลังจากที่เรียกเมธอดนี้จากมุมมองแล้ว ฉันต้องการดึงออบเจ็กต์ที่อัปเดตแล้ว ในการทำเช่นนั้น ฉันกำลังเชื่อมโยงเหตุการณ์ 'การเปลี่ยนแปลง' กับโมเดล แต่ไม่ได้กำหนด ID ที่กำหนดแยกวิเคราะห์ นี่คือรหัสของโมเดล:
var Match = Parse.Object.extend("Match", {
states: {'DRAFT': 0, 'RUNNING': 1, 'ENDED': 2},
saveDraftToP: function () {
var self = this;
this.save({
user: Parse.User.current(),
ACL: new Parse.ACL(Parse.User.current()),
state: self.states.DRAFT
}, {
success: function (result) {
self = result;
},
error: function (e) {
}
});
}
});`
และนี่คือรหัสสำหรับมุมมอง:
var vmNuovaPartita = Parse.View.extend({
template: Handlebars.compile(template),
model: new Match(),
collection: new HintCollection(),
initialize: function () {
this.bind("change:model", console.log(this.model.id) , this);
},
render: function (eventName) {
var match = this.model.toJSON();
$(this.el).html(this.template(match));
return this;
}
});