主干集合取回在成功调用中不运行任何东西,但是取回所有的东西

backbone collection fetch does not run anything inside the success call, but fetches all ok

本文关键字:任何东 集合 成功 调用 运行      更新时间:2023-09-26

我有一个集合,获取这一行:

console.info("before fetching drivesCollection");
this.drivesCollection.fetch({
  success: function() {
    console.info("inside fetching drivesCollection");
  },
  error: function(collection, response, options) {
     console.log('ERROR fetching drivesCollection ');
  }
});
console.info("after fetching drivesCollection");

的抓取工作如预期,错误回调永远不会被调用。之后,我可以看到收藏中的所有模型(200+)。问题是成功函数中的任何东西都没有被调用。我需要在这里放一个函数

我试图调试为什么使用集合定义的parse函数以某种方式跳过success函数,如下所示:

parse: function(response){
    console.log('starting parsing of drivesCollection');
    console.log(response.length);
    console.log(response);
    return response

},

它按预期工作,并返回插入到集合中的有效值…

任何想法为什么我的success函数从未运行?

我想到了两件事:

1)您的服务器没有发送有关内容类型的正确标头信息,其中快速修复方法是通过添加参数

强制使用获取JSON数据
this.drivesCollection.fetch({
  dataType: 'json',
  success: function() {
    console.info("inside fetching drivesCollection");
  }
});

2)或者,你错误地使用了主干。模型来获取集合,而不是主干。