1

I'm trying to tidy up my code a bit, therefore one step I wanted to do is to transform my declarative markup from my navigation menubar into a programmatic one. I simply wanted to extend the class of dijit/MenuBar and add my functions in there. This is what it looks like so far:

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();
    } // [...]
})});

Unfortunately I get an error message "c is null". I guess there might be a problem with the this-function-call on the inherited addChild-method.

Anybody an idea?

Thanks in advance!

4

2 に答える 2

0

why dont you try dojo.extend and just provide the defination of those functions which you want to overrid or provide new functions view that dojo.extend

于 2013-01-20T12:14:03.843 に答える
0

The logic to add child widgets should be done in the postCreate method. The following link will provide you a better understanding of the widget lifecycle.

http://dojotoolkit.org/documentation/tutorials/1.6/understanding_widget/

postCreate: function() {
  this.inherited(arguments);

  /* Ansicht */
  ...

  /* Hilfe */
  ...

  etc
}
于 2013-01-20T12:29:04.660 に答える