使用此:
this.model.save(null, {
success: function(model) {
app.router.navigate('items/' + model.get('id'));
this.render();
}
});
有人知道为什么model.get('id'(是未定义的,而model.id有来自服务器的新id吗?
Backbone模型上的.get方法将从模型的"attributes"属性(对象(中检索"attribute"(即属性(。它不会检索模型上不属于这些属性的属性-model.id是模型本身的属性。
success
回调接受三个参数-(model, response, options)
。
尝试response.id
或console.log
输出响应。