我正在使用Backbone js創建應用程序,如服務。每個應用程序都有一個user_id和一個已設置的application_id。每次主幹調用fetch(),save()或其他RESTful/ajax函數時,我都希望user_id和application_id自動與模型數據一起傳遞。在BackBone模型中自動傳遞Certian值Ajax函數
我知道我將不得不擴展骨幹模型,然後確保我所有的模型都是從這個模型擴展而來,但是我該如何修改以及如何調用父模型?
的僞例(不是很確定)
MyModel = Backbone.Model.extend({
save : function(data) {
data.application_id = 3;
data.user_id = 5;
parent.save(data);
}
});
Scores = MyModel.extend({
default : {
score : 0
}
});
//This should automatically grab the application id and user id
scores = new Scores();
scores.set('score', 5);
score.save()
如何正確地做到這一點?通過完成,我的意思是代碼中的一個點可以用於save(),fetch()和destroy()?
我一直在尋找的確切答案!也適用於收藏。謝謝。 –