我正在尝试稍微整理一下我的代码,因此我想做的一个步骤是将我的声明性标记从导航菜单栏转换为程序化标记。我只是想扩展 dijit/MenuBar 类并在其中添加我的功能。这是到目前为止的样子:
define([ "util/debugger", "dojo/_base/declare", "dojo/_base/lang", "dojo/on",
"dojo/ready", "dijit/MenuBar", "dijit/PopupMenuBarItem",
"dijit/MenuItem", "dijit/DropDownMenu" ], function(debug, declare,
lang, on, ready, MenuBar, PopupMenuBarItem, MenuItem, DropDownMenu) {
return declare("navMenu", [ MenuBar ], {
constructor : function(kwArgs) {
debug.log("constructor called", "navMenu.constructor()", 1);
lang.mixin(this, kwArgs);
/* Ansicht */
var subMenuAnsicht = new DropDownMenu({});
var item_showFilterBar = new MenuItem({
label : "Filterleiste anzeigen"
});
subMenuAnsicht.addChild(item_showFilterBar);
// [...]
var test = new PopupMenuBarItem({
label : "Ansicht",
popup : subMenuAnsicht
});
//---------
this.addChild(test); // <==== this is where dojo says "c is null"
//---------
/* Hilfe */
var subMenuHelp = new DropDownMenu({});
var item_showVersion = new MenuItem({
label : "Versionsinfo"
});
on(item_showVersion, "click", clickVersionInfo);
subMenuHelp.addChild(item_showVersion);
// [...]
this.addChild(new PopupMenuBarItem({
label : "Hilfe",
popup : subMenuHelp
}));
/* Meine Einstellungen */
var subMenuMySettings = new DropDownMenu({});
var item_showMySettings = new MenuItem({
label : "Meine Einstellungen"
});
subMenuMySettings.addChild(item_showMySettings);
// [...]
this.addChild(new PopupMenuBarItem({
label : "Meine Einstellungen",
popup : subMenuMySettings
}));
/* Administration */
// if (sessionHandler.getPermission == "admin") {
var subMenuAdmin = new DropDownMenu({});
var item_showUserManager = new MenuItem({
label : "Userverwaltung"
});
subMenuAdmin.addChild(item_showUserManager);
// [...]
this.addChild(new PopupMenuBarItem({
label : "Administration",
popup : subMenuAdmin
}));
// }
this.placeAt("navMenu");
this.startup();
} // [...]
})});
不幸的是,我收到一条错误消息“c is null”。我想继承的 addChild 方法上的 this-function-call 可能有问题。
有人有想法吗?
提前致谢!