0

私はかなり奇妙なものに出くわしました

コレクションを取得し、リセット イベントをリッスンしていますが、どういうわけかイベントが失われます

私はこの最小限の例を持っています:

$(function() {
  var collection = new Backbone.Collection();
  collection.url = 'http://localhost:9000/api/Usuario';
  collection.on('reset', function() {
    console.log('collection reset!');
  });
  collection.fetch();
});

ネットワークを調べると、リクエストが成功し、Web サービスが json データを返していることがわかります

しかし、cosole.log('collection reset!') コールバックが実行される方法はありません。

私が見逃している本当にばかげた何かがあるに違いない...

4

1 に答える 1

1

バックボーンのドキュメントから

It uses set to (intelligently) merge the fetched models, unless you pass {reset: true},

だから、これを使用すると問題が解決すると思います。

collection.fetch({
    reset: true,
    success: function() {
        // Do Something
        // This is called when all add, remove and update operations have been done
    }
});
于 2013-05-14T08:08:58.187 に答える