本文介绍了什么事件调用取()在Backbone.js的集合时触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序Backbone.js的,有一个行程集合持有旅行车型,这正与的localStorage 。我能叫 Trips.create(form_attributes)以创建和旅行保存到托多斯店

In my backbone.js app, there is a Trips collection that holds Trip models, which is working with LocalStorage. I am able to call Trips.create(form_attributes) to create and save a trip to the Todos store.

当我第一次加载我的应用程序,我称之为 Trips.fetch({成功:trips_fetch_success}) trips_fetch_success 接收,显示旅行车型的响应行程集合成立。

When I first load my app, I call Trips.fetch({ success: trips_fetch_success }), and trips_fetch_success receives a response that shows the Trip models that the Trips collection holds.

我试图绑定刷新更改事件到行程集合,但这些事件没有被抓住,让我相信我有这个错误的观念有关的事件 Trips.fetch 触发。

I have tried to bind refresh and change events to the Trips collection, but these events are not being caught, making me believe I have the wrong idea about which events Trips.fetch triggers.

我的问题:哪些事件是 Trips.fetch 触发?并且是事件触发的集合或在每个单独的旅行车型

My question: which events should Trips.fetch trigger? And are the events triggered on the collection or on each of the individual Trip models?

推荐答案

Col​​lection.fetch()将调用重置成功,这反过来会触发一个复位事件。以集合所有用户重置事件应接收事件。

Collection.fetch() will call reset on success, which in turn will trigger a 'reset' event. Any subscribers to the collections reset event should receive the event.

这里的关键是成功。我有这个问题,只发现骨干正默默地吞噬我的错误消息。传递一个错误处理程序,至少,日志的console.log(),看看发生了什么:

The key here is "on success." I had this problem, only to discover that backbone was silently swallowing my errors messages. Pass in an error handler that, at least, logs to console.log(), and see what's happening:

trips.fetch({error: function() { console.log(arguments); }});

(注:Backbone.js的旧版本将触发刷新,而不是复位)

(Note: Old versions of backbone.js will trigger "refresh" instead of "reset")

这篇关于什么事件调用取()在Backbone.js的集合时触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 09:04