ビューでレンダリングしようとしているバックボーン コレクションがあります。JSON データは正しいようですが、ビュー内から値にアクセスできません。
基本的なコレクションは次のとおりです。
define(['backbone', 'BaseModel'], function(Backbone, BaseModel) {
var BaseCollection = Backbone.Collection.extend({
model: BaseModel,
url: "/collection/get?json=true",
initialize: function() {}
});
return BaseCollection;
});
ビューは次のとおりです。
define(['backbone', 'BaseCollection'], function(Backbone, BaseCollection) {
var BaseView = Backbone.View.extend({
el: $('#baseContainer'),
template: _.template($('#baseTemplate').html()),
initialize: function() {
_.bindAll(this);
this.collection = new BaseCollection();
this.collection.bind('all', this.render, this);
this.collection.fetch();
},
render: function() {
//This returns 3 objects which is correct based on the JSON data being returned from the server
console.log(this.collection.toJSON());
var html = this.template(this.collection.toJSON());
this.$el.html(html);
return this;
},
});
return BaseView;
});
this.render
コレクション内のモデルごとに反復する必要があると思います。しかし、すべての反復が完了するまで「レンダリング」するべきではないため、よくわかりません。
どんな提案も素晴らしいでしょう!ありがとうございました!