Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js can';t在主干集合上迭代,可能是一个获取/绑定问题_Backbone.js_Handlebars.js_Backbone.js Collections - Fatal编程技术网

Backbone.js can';t在主干集合上迭代,可能是一个获取/绑定问题

Backbone.js can';t在主干集合上迭代,可能是一个获取/绑定问题,backbone.js,handlebars.js,backbone.js-collections,Backbone.js,Handlebars.js,Backbone.js Collections,我正在将一个用户朋友的列表收集到一个集合中,我想对这些朋友进行迭代,以便用户可以选择一个朋友,然后做一些事情 在我看来,我有 friends = new MyApp.Collections.UserFriends(); friends.fetch({ data: $.param({ search: this.model.attributes.user_id}), success: function(){ }, error:

我正在将一个用户朋友的列表收集到一个集合中,我想对这些朋友进行迭代,以便用户可以选择一个朋友,然后做一些事情

在我看来,我有

friends = new MyApp.Collections.UserFriends(); friends.fetch({ data: $.param({ search: this.model.attributes.user_id}), success: function(){ }, error: function(){ alert('error getting friends'); } }); friends.bind('fetched', this.render(),this); friends=新建MyApp.Collections.UserFriends(); fetch({data:$.param({search:this.model.attributes.user_id}), 成功:函数(){ }, 错误:函数(){ 警报(“获取朋友时出错”); } }); bind('fetched',this.render(),this); 那么在我的渲染中

console.log(friends); console.log(HandlebarsTemplates['friends/friendsResults'](friends); $(this.el).html(HandlebarsTemplates['friends/friendsResults'](friends); console.log(朋友); log(HandlebarsTemplates['friends/friendsResults'](friends); $(this.el).html(HandlebarsTemplates['friends/friendsResults'](friends); 我的车把坏了

ok, I have the right handlebar template {{#each models}} <li> {{attributes.username}}</li> {{/each}} 好的,我有右把手模板 {{{#每个模型}
  • {{attributes.username}
  • {{/每个}} 控制台中的friends集合是,因此我可以看到模型在那里

    byCid: Object _byId: Object _callbacks: Object length: 39 models: Array[39] __proto__: q byCid:对象 _byId:Object _回调:对象 长度:39 型号:阵列[39] __原型:q
    我担心的是,问题是在创建集合之前触发了渲染,但我认为
    friends.bind('fetched',this.render(),this)就是这样
    应该解决。

    主干中没有“获取”事件,请尝试使用“重置”。

    感谢Yaroslav,我尝试了
    重置
    ,但车把模板中仍然没有显示任何内容。我确信以前有人告诉我使用“获取”。并删除括号
    friends.bind('fetched',this.render/*()*/,this)
    (这个javascript…)