Dojo 事件未触发

发布于 2024-11-30 11:47:06 字数 940 浏览 6 评论 0原文

我有一个 Dojo 选项卡容器,当我单击某些按钮时,会动态添加一个新选项卡,其内容是通过 Ajax 下载的。这些选项卡包含动态表单元素,Dojo 可以很好地解析和加载这些元素。我还包括特定于每个选项卡的 Javascript 块,并且这些块也通过 Ajax 下载...但是,没有一个 Javascript 块执行!

选项卡内容示例:

<input id="test" name="test" type="text" dojoType="dijit.form.ValidationTextBox" />

<script type="text/javascript">
   dojo.connect(dijit.byId('test'), 'onClick', function(evt){
       alert('testing 123');
   });
</script>

但是,如果我这样做,事件触发就好了:

<input id="test" name="test" type="text" dojoType="dijit.form.ValidationTextBox">
    <script type="dojo/method" event='onClick'>
         alert('testing 123');
    </script>
</input>

我的问题是,为什么第一个示例中的 Javascript 块不起作用?这是 Dojo 的限制吗?另外,我还尝试在加载小部件后设置它们的属性和值。鉴于我必须使用诸如 dojo.addOnLoad() 之类的东西,我该如何激活它,它不起作用,因为它需要一个 Javascript 块,并且按照第一个示例不起作用......没有等效的小部件 onLoad 事件,所以我也不能使用第二种方法...有什么想法可以做到这一点吗?

I have a Dojo tab-container and when I click on certain buttons, a new tab is added dynamically with its contents downloaded via Ajax. The tabs contain dynamic form elements which are parsed and loaded by Dojo just fine. I am also including Javascript blocks which are specific for each tab and those are downloaded as well via Ajax... however, none of the Javascript blocks execute!

Example of tab content:

<input id="test" name="test" type="text" dojoType="dijit.form.ValidationTextBox" />

<script type="text/javascript">
   dojo.connect(dijit.byId('test'), 'onClick', function(evt){
       alert('testing 123');
   });
</script>

However, if I do this instead the events trigger just fine:

<input id="test" name="test" type="text" dojoType="dijit.form.ValidationTextBox">
    <script type="dojo/method" event='onClick'>
         alert('testing 123');
    </script>
</input>

My question is, why don't Javascript blocks in the first example work? is this a Dojo limitation? Also, I am also trying to set properties and values for the widgets AFTER they've been loaded. How do i active that given I have to use something like dojo.addOnLoad() which won't work because it requires a Javascript block and that doesn't work as per the first example... There is no equivalent widget onLoad event so I can't use the second method either... Any ideas how to go about doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

〆凄凉。 2024-12-07 11:47:06

“选项卡内容”实际上是一个内容窗格元素。除非使用

更新:如果您使用dojox.layout.ContentPane而不是dijit.layout.ContentPane,所有与其中的js有关的问题都会消失。来自 Dojo 参考指南:

dojox.layout.ContenPane 是 dijit.layout.ContentPane 的扩展,提供脚本执行等功能。

The "tab content" is actually a Content Pane element. You can't call a javascript inside a content pane unless you use <script type="dojo/method">. At least this is what I know.

Update: ifyou'll use dojox.layout.ContentPane instead of the dijit.layout.ContentPane all the problems regarding the js inside it will vanish. From Dojo Reference Guide:

dojox.layout.ContenPane is an extension to dijit.layout.ContentPane providing script execution, among other things.

清风夜微凉 2024-12-07 11:47:06

看起来您需要使用 dojo.hitch 以便您的函数在实际调用时位于范围内。尝试使用:

dojo.connect(dijit.byId('test'), 'onCLick', dojo.hitch(this, function(evt) {
      alert('testing123');
}));

您可以在这里阅读更多相关信息:http://dojotoolkit。 org/reference-guide/dojo/hitch.html#dojo-hitch

It looks like you need to use dojo.hitch so that your function will be in scope when it is actually called. Try using:

dojo.connect(dijit.byId('test'), 'onCLick', dojo.hitch(this, function(evt) {
      alert('testing123');
}));

You can read more about it here: http://dojotoolkit.org/reference-guide/dojo/hitch.html#dojo-hitch

黑寡妇 2024-12-07 11:47:06

您必须确保首先解析该小部件。这样做:

dojo.addOnLoad(function(){/*connect code*/});

You have to ensure that the widget has been parsed first. Do it like so :

dojo.addOnLoad(function(){/*connect code*/});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文