0

この質問は、以前のマリオネットのリージョンから別のリージョンへの切り替え、ビューが正しくレンダリングされない に基づいています。私が従っているアプローチが正しいかどうか、またはリージョン間の切り替えを実行する別のアプローチが存在するかどうかを尋ねているため、それとは異なります。

2 つの異なる領域を持つレイアウトを作成しました。レイアウトでは、レイアウトの2initializeつの領域に 2 つのビューが読み込まれます。ViewAと言うViewB。イベント内ViewAでトリガーされます。イベントはレイアウトによって消費されて切り替わり、他の 2 つのビューが挿入されます。ViewCと言うViewD

このアプローチは正しいですか、それとも別のパターンに従う必要がありますか? ルーティング?

コメントが重要な部分を強調するコードを次に示します。

onConfirm : function() {        
        this.leftView =  new ViewC();
        this.rightView = new ViewD();

        this.leftRegion.show(this.leftView);                                                                        
        this.rightRegion.show(this.rightView);
    },

initialize : function() {
        // listen for event triggered from ViewA
        // e.g. GloabalAggregator.vent.trigger("ga:confirm");
        // where "ga:confirm" is a simple string
        GloabalAggregator.vent.on("ga:confirm" , this.onConfirm, this);  

        this.leftView =  new ViewA(), // creating here a new ViewC the style is applied correctly
        this.rightView = new ViewB(); // creating here a new ViewD the style is applied correctly
    },

onRender : function () {
        this.leftRegion.show(this.leftView);                                                                        
        this.rightRegion.show(this.rightView);
    }
4

1 に答える 1

1

Layout通常、コントローラーが使用されるビューを切り替えるには、例としてこの要点を見てください。

基本的に、新しいコントローラーを作成する必要があります

var controller = Marionette.Controller.extend({
  initialize: function(options){
    this.leftRegion = options.leftRegion;
    this.rightRegion = options.rightRegion;
  },

  swap: function() {
    // do the region swapping here
  }
});

ビューから次のように作成できます。

var controller = new MyController({
  leftRegion: this.leftRegion,
  rightRegion: this.rightRegion
});

(ここでthisビューを参照します)、 listenTo の助けを借りてそのイベントをリッスンします

Marionette の作成者からの役立ついくつかの例を次に示します。

于 2013-08-09T15:50:54.777 に答える