本文介绍了Dojo不能以编程方式连接djits?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码:

var d = new dijit.Dialog({
    title: "Programatic Dialog Creation",
    style: "width: 300px",
});
var button1 = new dijit.form.Button({'label': 'one', 'onClick': function () {
        alert('one')
}});

var button2 = new dijit.form.Button({'label': 'two', 'onClick': function () {
        alert('two');
}});
d.attr("content", button1 + ' | ' + button2);
d.show();

预期结果:

实际结果:一个对话框与文本

Actual result: A dialog with the text

我做错了什么?完成此任务的正确方法是什么?
我试过dojo.place和dojo.query没有成功。

What am I doing wrong? What is the correct way to accomplish this task?I've tried dojo.place and dojo.query with no success.

推荐答案

你正在混合Dijit对象,DOM节点和字符串。

You are mixing up Dijit objects, DOM nodes and strings.

将Dijits放置到Dialog或任何容器小部件中的可行方式是:

The corrent way to place Dijits into Dialog or any container widget is:

dojo.place(button1.domNode, d.containerNode);
dojo.place(button2.domNode, d.containerNode);
d.show();

或者您可以在创建Dijit对象时调用placeAt()方法:

Or you can call placeAt() method when creating Dijit object:

var button1 = new dijit.form.Button({'label': 'one', 'onClick': function () {
    alert('one')
}}).placeAt(d.containerNode);

你得到了结果,因为基本上发生的是

You got your result because what basically happens is

d.attr("content", button1.toString() + '|' + button2.toString());

另请注意插入字符串是可能的:

Also note inserting strings is possible this way:

var button1Html = dojo.create("div").appendChild(button1.domNode).parentNode.innerHTML;
var button2Html = dojo.create("div").appendChild(button2.domNode).parentNode.innerHTML;
d.set("content", button1Html + "|" + button2Html);

但它不起作用,因为它创建了不在Dijit对象中引用的新DOM节点按钮),所以您的活动不会触发。

but it won't work, because it creates new DOM nodes that are not referenced in Dijit objects (buttons), so your events won't fire.

这篇关于Dojo不能以编程方式连接djits?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 14:30