初めてのバックボーン アプリケーションを開発しようとしています。すべて問題ないようですが、ビューをレンダリングして html を追加すると$el
、ページに何もレンダリングされません。残りのサービス呼び出しは正常に完了しました。DOM が確実に作成されるようにBackbone.Router.extend
内部で宣言されています。$(document).ready(function () {});
私のjavascriptをデバッグすると、要素はinnerHTMLel
プロパティに正しい値を含むようになりますが、ページ全体がレンダリングされると、この値はページに表示されません。
私は何を間違っていますか?
私のビューコード:
window.ProductsListView = Backbone.View.extend({
id: 'tblProducts',
tagName: 'div',
initialize: function (options) {
this.model.on('reset', this.render, this);
},
render: function () {
// save a reference to the view object
var self = this;
// instantiate and render children
this.model.each(function (item) {
var itemView = new ProductListItemView({ model: item });
var elValue = itemView.render().el;
self.$el.append(elValue); // Here: the $el innerHTML is ok, but in the page it disappear. The id of element is div#tblProducts, so the element seems correct
});
return this;
}
});
window.ProductListItemView = Backbone.View.extend({
tagName: 'div',
template: _.template(
'<%= title %>'
),
initialize: function (options) {
this.model.on('change', this.render, this);
this.model.on('reset', this.render, this);
this.model.on('destroy', this.close, this);
},
render: function () {
$(this.el).html(this.template(this.model.toJSON()));
// $(this.el).html('aaaaaa'); // This neither works: it's not a template problem
return this;
},
close: function () {
$(this.el).unbind();
$(this.el).remove();
}
});
ここで製品をロードします ( 内Backbone.Router.extend
)。これは正しく実行されます:
this.productsList = new ProductsCollection();
this.productsListView = new ProductsListView({ model: this.productsList });
this.productsList.fetch();
そして、これは私がレンダリングしたいhtml要素です:
<div id="tblProducts">
</div>
前もって感謝します、