Relational firing add event before server responds

I'm using Backbone-Relational in a project at the moment, and it's not behaving the way it seems like it should.

Let's say Model A has a HasMany relationship with Model B. Model A listens for an "add:model_b" event to render a necessary view for Model B whenever an instance is added to the Model A relationship. In order to render the view template properly though, we need some data from the server. From reading the backbone docs, it seems to me the logical way to do this would be as follows:

modelA.get("model_b").create(newModelData, {wait: true});

As Backbone-Relational implements relations as Backbone Collections, I just call the collection.create method to instantiate my new Model B, and pass {wait: true} to the options in order to delay the "add" event til the server responds.

However, this seems to have no effect: the "add" event is firing instantly, and I'm therefore getting an error when trying to render a view that needs data that is not yet part of the model. Does anyone know why {wait: true} is doing nothing in this instance, and how can I get the desired behavior out of Backbone-Relational?

链接地址: http://www.djcxy.com/p/65526.html

上一篇: 关系式不设置父模型或反向关系

下一篇: 服务器响应之前的关系触发添加事件