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从fetch()遍历JSON结果_Backbone.js - Fatal编程技术网

Backbone.js从fetch()遍历JSON结果

Backbone.js从fetch()遍历JSON结果,backbone.js,Backbone.js,我是个新手,只是想弄清楚事情的运作方式。如何遍历“获取的”结果 似乎调用了fetch(),因为“fieldmodelinit.”在控制台中出现了5次。但是如何输出呢?我想把这些项目附加到一个无序的列表中 谢谢 将重置事件绑定到渲染函数 this.collection.bind('reset', this.render, this); 这将在提取完成后触发,因此您可以创建列表 render: function() { var self = this; console.log('R

我是个新手,只是想弄清楚事情的运作方式。如何遍历“获取的”结果

似乎调用了fetch(),因为“fieldmodelinit.”在控制台中出现了5次。但是如何输出呢?我想把这些项目附加到一个无序的列表中

谢谢

将重置事件绑定到渲染函数

this.collection.bind('reset', this.render, this);
这将在提取完成后触发,因此您可以创建列表

render: function() {
    var self = this;
    console.log('Render called.');
    this.collection.each(function(i,item) {
        this.$el.append("<ul>" + item.get("field_name") + "</ul>");
    });
},
render:function(){
var self=这个;
log('Render called');
此.集合.每个(功能(i,项){
此.el.append(“
    ”+项.get(“字段名称”)+“
”); }); },
谢谢!但是我应该把
this.collection.bind('reset',this.render,this)放在哪里?我发布的代码只有一个“render”函数,但在您的回答中,我没有在您的呈现代码中看到reset事件。@wenbert,bind调用应该在initialize函数中。(在收集获取完成后,主干会调用Reset。)
this.collection.bind('reset', this.render, this);
render: function() {
    var self = this;
    console.log('Render called.');
    this.collection.each(function(i,item) {
        this.$el.append("<ul>" + item.get("field_name") + "</ul>");
    });
},