这个小提琴演示了两种方法,但我不知道是否有官方的方法可以做到这一点。
设置菜单:
var pMenu;
require(["dojo/ready", "dijit/Menu", "dijit/MenuItem", "dijit/PopupMenuItem"], function (ready, Menu, MenuItem) {
ready(function () {
pMenu = new Menu({
targetNodeIds: ["progmenu"]
});
pMenu.addChild(new MenuItem({
label: "Simple menu item"
}));
pMenu.startup();
});
});
function runAfterDelay(fn, ms) {
setTimeout(function () {
console.log("Timeout " + new Date());
fn();
}, ms);
}
添加事件处理。
- 方法 #1 是调用
dijit/popup.close()
,将菜单作为单个参数传递。
- 方法#2 合成一个
blur
事件来“欺骗”菜单关闭。
...
require(["dojo/dom", "dojo/on", "dijit/popup"], function (dom, on, popup) {
var timeout = 3000;
on(dom.byId("btnPopupClose"), "click", function () {
runAfterDelay(function () {
if (pMenu) {
console.log("Calling .close()");
popup.close(pMenu);
}
}, timeout);
});
on(dom.byId("btnTriggerBlur"), "click", function () {
runAfterDelay(function () {
var opts = {
bubbles: true,
cancelable: true
};
console.log("emitting blur event");
on.emit(pMenu.domNode, "blur", opts);
}, timeout);
});
});