我正在尝试渲染,但我不完全了解 javascript 并比较此错误:Uncaught ReferenceError: wrapper is not defined。我会在同一个视图中呈现集合获取的结果。
var HomeView = Backbone.View.extend({
template: Handlebars.compile(template),
events: {
},
initialize: function() {
console.log("inhomeview");
var amici = new Usercollection();
amici.fetch({
success: function() {
amici.each(function(object) {
console.log(object.toJSON());
var wrapper=object.toJSON();
});
},
error: function(amici, error) {
// The collection could not be retrieved.
}
});
this.render();
},
render: function() {
var context=wrapper;
var html =this.template(context);
this.$el.html(html);
return this;
}
});
return HomeView;
});