2012-08-09 1 views
9

私は、以下を使ってフェードトランジションを追加するためにすべてのリージョンをオーバーライドできることを知っています。Backbone.Marionette Fadeトランジションは特定の地域のみですか?

Marionette.Region.prototype.open = function(view){ 
    this.$el.hide(); 
    this.$el.html(view.el); 
    this.$el.fadeIn() 
} 

特定のリージョンまたはビューを上書きする方法はありますか?レイアウトには、他の領域を即座にレンダリングする必要がある一方で、フェードインしたい領域があります。

おかげで、あなたはカスタムRegionあなたが任意のバックボーンオブジェクトを定義することができる方法を定義し、その領域のタイプにこのコードを追加することができます

答えて

16

DK。


MyRegion = Backbone.Marionette.Region.extend({ 

    el: "#some-element", 

    open: function(view){ 
    this.$el.hide(); 
    this.$el.html(view.el); 
    this.$el.fadeIn(); 
    } 

}); 

MyApp.addRegions({ 
    myRegion: MyRegion 
}); 

地域定義にはelが含まれています。これを複数のリージョンで再利用したい場合は、ベース・リージョンを作成し、必要なリージョンごとにベース・リージョンを拡張する必要があります。


FadeInRegion = Backbone.Marionette.Region.extend({ 

    open: function(view){ 
    this.$el.hide(); 
    this.$el.html(view.el); 
    this.$el.fadeIn(); 
    } 

}); 

MyApp.addRegions({ 
    myRegion: FadeInRegion.extend({el: "#some-element"}), 
    anotherRegion: FadeInRegion.extend({el: "#another-element"}) 
}); 
+0

おかげで、Derickをしてマリオネットを作成していただきありがとうございます。 – dkleehammer

+0

チップDerickありがとう。私はコードスニペットをそのまま動作させることができませんでしたが、私は追加しました... Backbone.Marionette.Region.prototype.open.call(this、view、appendMethod); ... FadeInRegionのメソッドの下部に...それはすべて良かった。 –

+0

2番目のコードスニペットを機能させるには、2番目のスニペットを次のように変更してください。var FadeInRegion = Backbone.Marionette.Region.extend({ – krhorst

-1

私はちょうど使用される別のオプションは、アニメーションのためのopenメソッドをオーバーライドすることだったクラス名をテストするために、個別の設定ファイルを作成し、その設定ファイルのopenメソッドをオーバーライドして、条件付きのロジックすることでした。だからここでは、私はコーヒースクリプトとマリオネットモジュールを使用しています。

私のビューを作成します:

@Item.module "ItemApp.Add", (Add, App, Backbone, Marionette, $,_) -> 

    class Add.Item extends Marionette.ItemView 

     template: "#add-item" 
     className: "add-modal" 

そして、私のconfigファイルで私は希望のアニメーションを実行するためにクラス名をテスト:

do (Marionette) -> 
    _.extend Marionette.Region::, 
     open: (view) -> 
      if view.el.className == "add-modal" 
       console.log "the add-modal has been called" 
       @$el.hide() 
       @$el.html(view.el) 
       @$el.show().animate "left": '0', queue: false 
関連する問題