简体   繁体   English

JSON的骨干更新集合

[英]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... ? 是否有一种解决方案来更新集合或唯一的方法是fetch集合...?

Check the value of "e" and "data" by debug in browser or console.log() or alert. 通过在浏览器或console.log()或警报中进行调试来检查“ e”和“数据”的值。 In my opinion your code might looked like below 我认为您的代码可能如下所示

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

帮助了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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