2016-04-01 13 views
0

私はルート付きのバックボーンアプリで自分のネストされたビューをナビゲートしたいと思います。私は次のコードを持っている:ルートがあるときバックボーンルートを持つネストされたビュー

var StoreRouter = Backbone.Marionette.AppRouter.extend({ 

    appRoutes: { 
    'item/:name/' : 'showItem', 
    "item/:name/species/:speciesName/" : "showSpecies" 
    } 

}); 

var StoreCtrl = Marionette.Object.extend({ 

    showItem: function(name){ 
    console.log("showItem"); 
    /* execute function for show Item */ 
    }, 

    showSpecies: function(name, speciesName){ 
    console.log("showSpecies"); 
    /* execute function for show Species inside Item Layout */ 
    } 

}); 

だから、私は種を表示する必要がある「の項目/:名前/種/:speciesNameは/」しかし、私だけではない、両方、showSpeciesのfucntionをトリガます。ルートが "item /:name/species /:speciesName /"のときにshowItemをトリガーしてからshowSpecies関数を呼び出すにはどうすればよいですか?

答えて

1

ここには全く新しいものはありません。 showItem機能をshowSpeciesから直接呼び出すだけです。
また、あなたの代わりにappRoutesroutesハッシュを使用することができますし、そうすることが可能である:

var StoreRouter = Backbone.Marionette.AppRouter.extend({ 

    routes: { 
    'item/:name/' : 'showItem', 
    'item/:name/species/:speciesName/' : function(){ 
     this.showItem(); 
     this.showSpecies(); 
    } 
} 

});

+0

ありがとうございます。しかし、私の場合、このソリューションは、別の種を見せたいときに毎回アイテムを再読み込みさせます。 /:speciesName/changesのときにアイテムをリロードして適切な種だけを表示する方法はありますか?もちろん、@PavelPoberezhnyi –

+0

。あなたの現在のアイテムのどこかに保存し、 'showItem'関数の最初にチェックを付け加えることができます:' if(currentItem === newItem)return false; ' –

+0

ありがとう –

関連する問題