In my view's method below, my model gets synced with the server if I understand the create()
method properly. However, the console.log
of this.model.id
still returns undefined
and this.model.isNew()
returns true
. The POST shows an id in the return JSON object and the model object attributes show an id as well, so why are they not reflecting properly in the model? I need the id to be set when I create the new view.
submitForm: function( e ) {
e.preventDefault();
this.model.set( this.$( '.editForm' ).serializeObject() );
if ( this.model.isNew() ) {
collection.create( this.model );
console.log( this.model, this.model.id, this.model.isNew() );
new MyView({
model: this.model
}).render().appendNode();
} else {
this.model.save();
}
this.closeForm();
}