我已经通过集合和使用函数获取,toJson()
结果是这样的:
对象{结果:数组[4]};
所以我将此对象传递给车把,但比较错误:
未捕获的类型错误:无法读取未定义的属性“对象”。
var wrapper;
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());
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);
console.log(html);
$('#pagina').html(this.$el.html(html));
}
});
return HomeView;
});
模板是这样的:
<section id="home">
<button>Scream</button>
<input type="text" name="scream">
<button>mt</button>
<section class="lista">
<ul>{{#each Object}}
<li>
<a href="#user/{{objectId}}">
<img src="{{avatar.url}}" width="69" height="69" />
<h3> {{username}} {{email}}</h3>
<h4>7 m</h4>
<h5>32 min</h5>
</a>
</li>{{/each}}</ul>
</section>
</section>