[英]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.