我正在学习骨干/木偶 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');
}
});
});
});
谢谢你的帮助 :) !