私のMarionette.CompositeView
場合、サーバーに put リクエストを行う新しいモデルを作成することが可能になります(1)。
put リクエストは問題ありませんが、新しいモデルをコレクションに追加すると、サーバーによって作成された 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
}
});