How do you handle this type of update in backbone.js?
This object lives on the client:
{
item1: {thing1:'one', thing2:'two'},
item2: {thing1:'one', thing2:'two'}
}
This gets sent from the server.
{
item1: {thing1:'ten', thing2:'twenty'},
item2: {thing1:'one', thing2:'two'},
item3: {thing1:'ten', thing2:'twenty'}
}
Each item is a view and DOM element.
How do I know when to update an existing view/dom element and when to add a ne开发者_Python百科w view/dom element?
You create a model and a collection for this model. Once you call fetch on the collection, backbone willc all your backend and fetch the new data. Once it is finished processing the query and received the data it will trigger a refresh event on the collection. Listen to that event and refresh the UI accordingly.
精彩评论