【发布时间】:2013-07-03 14:06:23
【问题描述】:
我正在学习主干/木偶 js,并且我正在使用样板来这样做:https://github.com/BoilerplateMVC/Marionette-Require-Boilerplate-Lite
我创建了 2 个视图(欢迎 / 文件)和 2 个区域:主要和标题。
在我的 headerRegion 中有我的导航栏,我想在更改或重新加载时处理我的菜单的“活动”类(模板:header.html)......但我不知道什么是最好的方法去做吧
我在 App.js 中定义了一个区域:
App.addRegions({
headerRegion:"header",
mainRegion:"#main"
});
在我的控制器中,我在初始化时创建了一个新的 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');
}
});
});
});
感谢您的帮助:)!
【问题讨论】:
标签: marionette init nav region