简体   繁体   中英

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 new 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM