在我的Marionette.CompositeView
中,可以创建向服务器(1)发出放入请求的新模型。
放入请求是好的,但是当我将新模型添加到集合中时,新模型会忽略由服务器创建的ID。
我应该如何解决这个问题?如何在创建保存新模型时获取ID
应该
1)POST请求发送ID到客户端或
2)我必须作出从客户的请求,以获得ID?
(1)
return Marionette.CompositeView.extend({
submitForm: function (event) {
this.textAreaElement = this.$el.find('[data-tid="announcement"]');
this.messageModel = new MessageModel();
this.messageModel.save({
message: this.textAreaElement.val()
}, {
wait: true,
success: this.onSuccess,
error: this.onError
});
},
onSuccess: function() {
console.log(this.messageModel.get('id')); // undefined
this.collection.add(this.messageModel); // I need to get also the id of the following model
// which is created by the server
}
});
我没有更新我的问题,把选项'等待:true'。你能检查它吗?谢谢。 Unforunatilly当我在onSuccess函数中获取id时,id是未定义的。它应该是服务器问题吗? – js999 2012-07-26 07:52:24
是的,服务器需要发送你想要的模型的ID和任何其他值 – 2012-07-26 11:00:36