は、モデルの各ビューをDOM内の既存の各DIV(divとwidget配列を持つhaveとdiv.container)にアタッチする方法を理解できません。モデルのビューをバックボーンの既存のDIVにアタッチする
$('#preview').on('load', function() {
var ShortcodesCollection = new V.Collections.Shortcodes(Vision.ShortcodeStorage);
var Preview = new V.Views.Preview({
collection: ShortcodesCollection,
el: $('.container')
});
Preview.render();
});
コレクションとプレビューをレンダリングします:各モデルの
// Collection View in iframe
V.Views.Preview = Backbone.View.extend({
initialize: function() {
this.collection.on('add', this.addOne, this);
},
render: function() {
this.collection.each(this.addOne, this);
return this;
},
addOne: function(ad) {
var shortcodeView = new V.Views.Shortcode({ model: ad });
shortcodeView.render();
}
});
ビュー:
をインラインフレームロード、コレクションにサーバからのプッシュストレージが// Model
V.Models.Shortcode = Backbone.Model.extend({});
// Shortcodes Collection Init
V.Collections.Shortcodes = Backbone.Collection.extend({
model: V.Models.Shortcode,
});
// Shortcode View V.Views.Shortcode = Backbone.View.extend({ events: { 'click .widget' : 'SomeActionOnView' }, render: function(){ //console.log(this.el); //console.log(this.model.toJSON()); }, SomeActionOnView: function(){ console.log(this); } });
質問は、イベントをバインドする "widget"クラスを持つ各divにV.Views.Shortcodeを添付する方法です。ありがとう!
divの下にあるすべてのビューをクラス「ウィジェット」で追加しますか? – Nitesh
@Niteshはそれぞれの.widgetに各ビューを追加したい – 20yco
すべてのビューに対して新しいdiv.widgetを作成する必要がありますか? – Nitesh