我正在尝试整理我的代码,因此我想做的一步是将我的声明性标记从我的导航菜单栏转换为程序化的标记。我只是想扩展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可能存在问题。
有人有想法吗?
提前致谢!
答案 0 :(得分:0)
为什么不尝试dojo.extend并只提供要覆盖或提供新功能的那些函数的定义 查看dojo.extend
答案 1 :(得分:0)
添加子窗口小部件的逻辑应该在postCreate
方法中完成。以下链接将帮助您更好地了解小部件生命周期。
http://dojotoolkit.org/documentation/tutorials/1.6/understanding_widget/
postCreate: function() {
this.inherited(arguments);
/* Ansicht */
...
/* Hilfe */
...
etc
}