Backbone.js从fetch()遍历JSON结果
我是个新手,只是想弄清楚事情的运作方式。如何遍历“获取的”结果 似乎调用了fetch(),因为“fieldmodelinit.”在控制台中出现了5次。但是如何输出呢?我想把这些项目附加到一个无序的列表中 谢谢 将重置事件绑定到渲染函数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
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>");
});
},