2013-10-16 31 views

cevap

28

Geçiş this: Bir CompositeView ve ItemView ile Nasıl yaptın

var ChildView = Backbone.View.extend({ 
    initialize : function (options) { 
    this.parent = options.parent; 
    } 
}); 

// somewhere in the parent view ... 
new ChildView({parent:this}); 
+0

? Marionette – hakunin

+0

@hakunin aynı şekilde yapabilirsiniz. Sadece uygun görünümü kullanın örn. 'Backbone.View' yerine" Marionette.ItemView " –

+0

Aynı şekilde değil - CollectionView durumunda çocuk görünümünü kendiniz oluşturmazsınız, bu nedenle childViewOptions veya bunun yerine bir şey kullanmanız gerekir. Her neyse, triggerMethod ile geçerken bile ekstra bir çaba gerektirmediğini gördüm. – hakunin

-2
// You can use this code instead 

var ChildView = Backbone.View.extend({ 
    initialize : function (options) { 
    this._configure(options); // Set all the options as local variables 
    // This is used in the Backbone.View code on the latest version 

    } 
}); 
+0

Omurga kaynağının herhangi bir yerinde '_configure'ı görmüyorsunuz. Ben de _.extend (bu, _pick (options, viewOptions)) 'ı görüyorum. Bu durumda, şöyle kullanılır: '_.extend (this, _.pick (options, ['parent'])); –