Marionette.CollectionView
のリストをレンダリングする がありますItemView
。render()
では、ItemView を使用してRaphaelmodel
を使用して SVG を描画します。
Raphael では、キャンバスの高さと幅を指定する必要があり、通常は から取得しthis.$el
ます。ただし、$el
(空の として) には、DOM に追加され、CSS ルールが適用されるまでディメンションがないため、ビューが DOM にあることがわかる<div>
までレンダリングを遅らせる必要があります。
問題はMarionette.CollectionView
、子ビューがレンダリングされるまで DOM に追加されないことです。の半分を再実装せずに、この動作をオーバーライドするにはどうすればよいCollectionView
ですか?
サンプルコード
// Renders a single object.
var ItemView = Marionette.ItemView.extend({
template: "#item-view-template",
onRender: function() {
var svgEl = this.$el.find("div.svg-canvas");
// Raphael needs the element's width and height, which
// is 0 until this.$el is in the DOM.
var paper = Raphael(svgEl.get(0), svgEl.height(), svgEl.width());
// ... draw some SVG...
}
});
// Renders a collection of objects.
var ListView = Marionette.CollectionView.extend({
itemView: ItemView,
model: MyModel
});
// Main point of entry.
MyApp.show = function() {
var collection = new MyCollection();
var listView = new ListView({ collection: collection });
MyApp.mainRegion.show(listView);
collection.fetch();
};