コレクションごとに取得し、関数toJson()
を使用した結果は次のとおりです。
オブジェクト {結果: 配列[4]};
したがって、このオブジェクトをハンドルバーに渡していますが、エラーを比較しています:
キャッチされていない TypeError: 未定義のプロパティ 'Object' を読み取ることができません。
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>