简体   繁体   English

我如何从发布响应中更新lobes.js中的集合?

[英]how do I update a collection in backbone.js from a post response?

I'm writing basically a folder browser in JavaScript, that starts at some folder on my server and every time you click a file I want the server to send me back a list of all the folders in that directory... but the problem is I can't seem to figure out how to update my backbone collection with the new data returned by the server when i do this.model.save()... I see in my web inspector that the response is being sent, so how do I update a collection; 我基本上是用JavaScript编写一个文件夹浏览器,该浏览器从服务器上的某个文件夹开始,每次单击文件时,我都希望服务器向我发送该目录中所有文件夹的列表...但是问题是当我执行this.model.save()时,我似乎无法弄清楚如何使用服务器返回的新数据更新主干集合。我在Web检查器中看到正在发送响应,因此如何我如何更新收藏集? flushing out all the old data and updating it with the new data that was returned by the server? 冲洗掉所有旧数据并用服务器返回的新数据进行更新?

any help with this would be greatly appreciated. 任何帮助,将不胜感激。

You are meaning collection.fetch. 您的意思是collection.fetch。 To do the server call: 要进行服务器调用:

this.collection.fetch();

To listen in the view the change: 要在视图中侦听更改:

this.collection.on('add', this.newModel);

Also in previous bakcbone version you could listen to the reset event instead of add. 同样在以前的bakcbone版本中,您可以侦听reset事件,而不是添加事件。 You could get more info about usage here: http://backbonejs.org/#Collection-fetch 您可以在此处获得有关用法的更多信息: http : //backbonejs.org/#Collection-fetch

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

相关问题 如何更新集合中的所有模型-Backbone.js - How can I update all models in a collection - Backbone.js 在Backbone.js中,我在集合下“创建”模型后,如何更新该模型? - In Backbone.js, after I 'create' a model under a collection, how do I update that model? 如何使用Backbone.js将过滤的集合转换为JSON? - How do I convert a filtered collection to JSON with Backbone.js? Backbone.js-如何将集合保存到localStorage? - Backbone.js - How do I save a collection to localStorage? Backbone.js-如何从集合中获取值? - Backbone.js - How I can get values from collection? 如何通过其ID从Backbone.js集合中获取模型? - How do I get a model from a Backbone.js collection by its id? Leaflet + Backbone.js:如何在模型集合更新中更新视图? - Leaflet + Backbone.js: how to update the view on model collection update? Backbone.js:我正在使用Web服务调用来使用Backbone.js获取集合对象,如何在html中显示集合响应对象数据? - Backbone.js: I am using web service call to get collection object using Backbone.js, How to display the collection response object data in html? 如何更新数据库中的整个Backbone.js集合? - How to update the whole Backbone.js collection that in database? 我在哪里将代码引导集合到belimber.js? - Where do I put the code to bootstrap a collection into backbone.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM