我一直在使用dojo 1.8 框架来创建一个包含其他一些菜单小部件的小部件。当我创建它的实例时,它会出现,但仅显示基本模板元素,并且在仔细检查下,尚未添加菜单小部件。然后,当我创建它的第二个实例(通过按钮单击)时,它会正确显示,包括菜单。
这真的让我很困惑,有什么想法吗?
哦,顺便说一下,我正在小部件实例上调用 startup()。
这是我的模板的代码...
<div class="${!baseClass}ConfigPanel">
<div data-dojo-attach-point="heading">Configure data</div>
<div id="menuContainer" data-dojo-attach-point="menu"></div>
</div>
这是我的小部件的代码...
define(
["dojo/_base/array",
"dijit/Menu",
"dijit/MenuItem",
"dijit/PopupMenuItem",
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dojo/text!gdv/chart/configuration/panel/chartConfigTemplate.html",
"dojo/domReady!"],
function (ArrayUtil, Menu, MenuItem, PopupMenu, declare, WidgetBase, TemplatedMixin, template){
var _menuData = [{title:"Region", data:["Region1", "Region2", "Region3"]},
{title: "Variable", data:["variable1", "variable2", "variable3"]},
{title: "Period", data:["period1", "period2"]},
{title: ["latest", "rt1", "rt2"]}];
/**
* Build menu items up with a popup menu style
*/
function buildMenu(nodeId, menuItems){
var mainMenu = new Menu({label: "main menu"}, nodeId);
var subMenuCollection = [];
var subMenu;
ArrayUtil.forEach(menuItems, function(item, index){
subMenu = new Menu({label: item.title});
subMenuCollection.push(subMenu);
//loop through each item in data and create a new menu item from it
ArrayUtil.forEach(item.data, function(subItem, subIndex){
subMenu.addChild(new MenuItem({label: subItem}));
});
//set the sub menu to popup from the main menu
mainMenu.addChild(new PopupMenu({label: item.title, popup: subMenu}));
});
//create the menus
mainMenu.startup();
//start each sub menu
ArrayUtil.forEach(subMenuCollection, function (item, index){
item.startup();
});
}
//return a new widget class
return declare([WidgetBase, TemplatedMixin], {
templateString: template,
baseClass: "plumePlots",
//when dom structure is ready but before page insertion
postCreate: function(){
//run all parent postCreate functions
this.inherited(arguments);
var menuNode = this.menu;
buildMenu(menuNode.id, _menuData);
}
});
}
)