What events are triggered when calling fetch() on a Backbone.js collection?

后端 未结 3 460
孤城傲影
孤城傲影 2020-12-13 12:07

In my backbone.js app, there is a Trips collection that holds Trip models, which is working with LocalStorage. I am able to call

3条回答
  •  再見小時候
    2020-12-13 12:26

    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.

    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); }});
    

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

提交回复
热议问题