简体   繁体   中英

Backbone update collection with json

I have a backbone collection with models.

I use file upload plugin:

$('#file-areas-fileupload').fileupload({
          ....
          dataType: 'json',
          done: function (e, data) {
               self.collection.parse(data.result);
          }
      });

And i want to update existing models in collection when response has come. But:

self.collection.parse(data.result);
self.collection.add(data.result);

Is not working. Is there a solution to update collection or only way is to fetch collection... ?

Check the value of "e" and "data" by debug in browser or console.log() or alert. In my opinion your code might looked like below

self.collection.parse(e.result);
self.collection.add(e.result);
self.collection.set(response.result)

帮助了

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