Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rv-each updates only newly added rows in a list #480

Closed
pawelmurawski opened this issue Apr 28, 2015 · 3 comments
Closed

rv-each updates only newly added rows in a list #480

pawelmurawski opened this issue Apr 28, 2015 · 3 comments

Comments

@pawelmurawski
Copy link

Check out this fiddle: https://jsfiddle.net/fsjvg0w5

After clicking "Add" button new row is added but "howmany" value is updated only for this new row, for every other it stays old. Is it an expected behaviour of RivetJS or is it a bug? If it is an expected behaviour then why it cannot work in a way when every row is updated when a model changes?

@Duder-onomy
Copy link
Collaborator

Here is your fiddle with the minimun number of changes it took to get it working like you said:
http://jsfiddle.net/rzdkq5xn/

I changed your bind call to bind an object with a property called state:

rivets.bind($table, {state : state});

Then I access the properties rows and howmany from the state property on the bound object:

<tr rv-each-row="state.rows" style="border: 1px solid black">

<td rv-text="state.howmany"></td>

@Duder-onomy
Copy link
Collaborator

BTW. I am not 100% sure why this happens, but I believe it is related to - #452 especially the findings of @tayfunyugruk

It seems like, when you incremented the howmany property, and it was the root property on the binding, that it replaced the reference to the property, so that each time you incremented it, it was a 'new' howmany property.

By putting the property on a object, then modifying that object the reference is maintained.

Hope this helps.

@pawelmurawski
Copy link
Author

It works like a charm! Thank you for help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants