1

使用这个:

        this.model.save(null, {
            success: function(model) {
                app.router.navigate('items/' + model.get('id'));
                this.render();
            }
        });

有没有人知道为什么 model.get('id') 是未定义的,但是 model.id 有来自服务器的新 id?

4

2 回答 2

4

Backbone 模型上的 .get 方法将从模型的“属性”属性(对象)中检索“属性”(即属性)。它不会检索模型上不属于这些属性的属性 - model.id 是模型本身的属性。

于 2013-03-22T19:22:10.433 回答
0

success回调接受三个参数(model, response, options)- .

尝试response.idconsole.log做出回应。

于 2013-03-23T00:21:17.947 回答