Javascript JSFIDLE中的Dijit对话框立即启动-而不是单击

Javascript JSFIDLE中的Dijit对话框立即启动-而不是单击,javascript,dojo,Javascript,Dojo,我正在努力让Dijit对话框为一个可复制的示例工作。我从中获取了工作代码,并尝试将其转换为命名函数,以便在整个示例中使用 作者使用: new Button({label: 'Show dialog', onClick: function() { //Create dialog programmatically here } }); 但我已经将此更改为稍微不同: function launchSelectDialog(selectOptions) { //Create dialog

我正在努力让Dijit对话框为一个可复制的示例工作。我从中获取了工作代码,并尝试将其转换为命名函数,以便在整个示例中使用

作者使用:

new Button({label: 'Show dialog', onClick: function() {
   //Create dialog programmatically here
}
});
但我已经将此更改为稍微不同:

function launchSelectDialog(selectOptions) {
    //Create dialog programmatically here
}
registry.byId("default-launch", "onClick", launchSelectDialog(allOpts));
不幸的是,这只是在加载页面时立即启动对话框,而在单击按钮时再也不会启动对话框

我已经检查了JSFIDLE中的NoWrap选项。关于发生了什么我没有其他线索。 如果您有任何想法,请提供帮助。

()
是一个调用操作符。您自己正在调用函数,函数的返回值被设置为事件处理程序。如果要重用该函数,请使用闭包:

function launchSelectDialog(selectOptions) {
    // the returned function will be used as the event handler
    return function() {
       // the passed `selectOptions` is remembered in this context
    }
}
另一个选择是:

registry.byId("default-launch", "onClick", function() {
   launchSelectDialog(allOpts);
});
()
是一个调用运算符。您自己正在调用函数,函数的返回值被设置为事件处理程序。如果要重用该函数,请使用闭包:

function launchSelectDialog(selectOptions) {
    // the returned function will be used as the event handler
    return function() {
       // the passed `selectOptions` is remembered in this context
    }
}
另一个选择是:

registry.byId("default-launch", "onClick", function() {
   launchSelectDialog(allOpts);
});

在使用注册表.byId()进行检索之前,您需要启动按钮小部件。。 在您的代码中,实际上
registry.byId(“默认启动”)
正在返回
未定义的

另外,
registry.byId()
函数只接受
id
,因此其他参数将被忽略

要修复它,您应该正确地启动一个按钮实例,并在
onClick
中声明
launchSelectDialog(allOpts)
,如下所示:

  var myButton = new Button({
    label: "Default Options",
    onClick: function() {
      launchSelectDialog(allOpts);
    }
  }, "default-launch");
下面是脚本的固定版本


在使用注册表.byId()进行检索之前,您需要启动按钮小部件。
。 在您的代码中,实际上
registry.byId(“默认启动”)
正在返回
未定义的

另外,
registry.byId()
函数只接受
id
,因此其他参数将被忽略

要修复它,您应该正确地启动一个按钮实例,并在
onClick
中声明
launchSelectDialog(allOpts)
,如下所示:

  var myButton = new Button({
    label: "Default Options",
    onClick: function() {
      launchSelectDialog(allOpts);
    }
  }, "default-launch");
下面是脚本的固定版本


有两个问题

1) 正如其他人所指出的,您正在调用函数,而不是使用函数设置事件。因此,该对话框在加载时可见

2) 您需要等待html被解析。或者您需要使用
parser.parse()


这是最新的小提琴手:

有几个问题

1) 正如其他人所指出的,您正在调用函数,而不是使用函数设置事件。因此,该对话框在加载时可见

2) 您需要等待html被解析。或者您需要使用
parser.parse()


下面是更新后的fiddler:

如果使用
parser.parse()
我建议使用parser.parse().then()使用它;非常感谢你!这就解释了一切。如果使用
parser.parse()
,我建议使用parser.parse().then();非常感谢你!这解释了一切。