Backbone Model save - this.model.get('id') undefined



使用此:

        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.idconsole.log输出响应。

最新更新