不能赶上主干收藏复位事件 [英] can't catch Backbone Collection reset event

查看:125
本文介绍了不能赶上主干收藏复位事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经横跨东西很奇怪跌跌撞撞

I've stumbled across something quite strange

我获取一个集合,并侦听复位事件,但不知何故,该事件被丢失

I'm fetching a collection, and listening on the reset event, but somehow the event is lost

我有这样的小例子:

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

检查网络,我可以看到该请求seuccessful和Web服务返回JSON数据

Inspecting the network I can see that the request is seuccessful, and the web service returns json data

但没有办法了cosole.log('集合复位!')被执行回调。

But there's no way that the cosole.log('collection reset!') callback is executed.

有必须有一些非常愚蠢的我失踪...

There must be something really silly that I'm missing...

推荐答案

骨干文档

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

所以我想,使用此将解决你的问题。

So I guess, Using this will solve your problem.

collection.fetch({
    reset: true,
    success: function() {
        // Do Something
        // This is called when all add, remove and update operations have been done
    }
});

这篇关于不能赶上主干收藏复位事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆