0

我正在学习骨干/木偶 js,并且我正在使用样板来这样做:https ://github.com/BoilerplateMVC/Marionette-Require-Boilerplate-Lite

我创建了 2 个视图(欢迎 / 文件)和 2 个区域:电源和标题。

在我的 headerRegion 中有我的导航栏,我想在更改或重新加载时处理菜单的“活动”类(模板:header.html)......但我不知道什么是最好的方法

我在 App.js 中定义了一个区域:

App.addRegions({
        headerRegion:"header",
        mainRegion:"#main"
});

在我的控制器中,我在 init 上创建了一个新的 HeaderView:

initialize:function (options) {
        App.headerRegion.show(new HeaderView(options));
}

这是我的 HeaderView :

define([ 'marionette', 'handlebars', "App", 'text!templates/header.html'],
function (Marionette, Handlebars, App, template) {
    //ItemView provides some default rendering logic
    return Marionette.ItemView.extend({
        template:Handlebars.compile(template),
         initialize: function (options) {
          _.bindAll();
        },
        onRender : function(options){
          $('ul.nav li', this.$el).removeClass('active');
        }
    });
});

});

谢谢你的帮助 :) !

4

1 回答 1

0

在 Marionette 的书中所做的是使用 Backbone.picky 来管理哪个标头模型是活动的,并在这种情况下添加适当的 CSS 类。您可以在此处查看相关的标头模型选择:https ://github.com/davidsulc/marionette-gentle-introduction/blob/master/assets/js/apps/header/list/list_controller.js

当用户通过直接 URL(例如书签)进入应用程序时,我设置了正确的活动标题(例如https://github.com/davidsulc/marionette-gentle-introduction/blob/master/assets/js/应用程序/联系人/contacts_app.js

于 2013-07-03T14:18:04.407 回答