azproduction / rivets-backbone-adapter

Backbone.js adapter for Rivets.js data-bind with nested models and collections support
http://azproduction.github.io/rivets-backbone-adapter/example/index.html
MIT License
48 stars 15 forks source link

Not binding when fetching collection #16

Closed frenic closed 9 years ago

frenic commented 9 years ago

Hi guys,

Thanks for a great work. But I'm having trouble making bindings work correctly with nested models when merging new data into the main collection using the fetch method.

I've simulated the behavior: http://jsfiddle.net/Faddee/f9uqrvo7/

In this case I'm using Backbone Associations, but I get the similar behavior using Backbone Relations.

The "Update" button sets the entire collection again but with model 3 replaced with model 4. This triggers the remove-event on model 3 and add-event on model 4, but nothing happens. Model 1 and 2 are intact and the change occurs correctly.

Same thing with the "Reset" button. The reset-event triggers but nothing happens.

But if i change:

<div rv-each-list=":models">

to

<div rv-each-list=".models">

It looks like it's working, but whats really happening is that everything rebinds (except for model 1 when you click the "Update" button for some reason).

Don't know if I'm doing something wrong or if this is an related issue to the adapter? Let me know if a can assist in any way!

azproduction commented 9 years ago

Thank you for your question and sorry for the late response. Is this one fixes your case http://jsfiddle.net/f9uqrvo7/49/ ?

azproduction commented 9 years ago

I revisited my code one more time and decided that :-adapters should work only with attributes of Models. Now it accesses properties of Collections along with Model attributes. But in this case one should use a native adapters - .

So, in future version 2.1.0 expression :models will return undefined if called on Backbone.Collection or any other non-Backbone.Model object.

Example with future version of this adapter: http://jsfiddle.net/f9uqrvo7/51/

azproduction commented 9 years ago

To work with a new version, please, use <div rv-each-list=".models"> or wrap collection with Backbone.Model:

rivets.bind(this.el, new Backbone.Model({
    lists: lists
}));

and then use <div rv-each-list=":lists">

frenic commented 9 years ago

Thanks a lot, works like a charm!