使用 dojo 修改 div 的文本

发布于 2024-10-08 18:47:18 字数 595 浏览 0 评论 0原文

我有一个 dojo 小部件。对于小部件,我有 2 个文件 A.js 和 A.html。现在在 A.html 中,我有类似的内容

<div id ="xyz" dojoAttachpoint="xyz"> </div>  

上面的行是小部件模板中的一行,它是一个普通的 html div

现在在 A.js 中我对服务器进行异步调用。在远程方法的回调函数中,我想修改跨度xyz的文本。我尝试了以下3种方法,但没有一种有效。

1) dojo.byId("xyz").innerHTML = "一些文本"
2) this.xyz.innerHTML ="some text"

3)

 var myWidget = dijit.byId("pack1.abc.widget.widgetname_id");
            myWidget.xyz.innerHTML ="some text"

上述方法均无效。

当我在 A.js 的其他函数(非回调函数)中使用方法 1 时,它工作得很好。

I have a dojo widget.For widget i have 2 files A.js and A.html.Now inside A.html i have something like

<div id ="xyz" dojoAttachpoint="xyz"> </div>  

The above line is one line inside the widget template and its a normal html div

Now in A.js i make a asynchronous call to server.In the callback function of remote method i want modify the text of span xyz.I tryed following 3 ways, but none of them is working.

1) dojo.byId("xyz").innerHTML = "some text"
2) this.xyz.innerHTML ="some text"

3)

 var myWidget = dijit.byId("pack1.abc.widget.widgetname_id");
            myWidget.xyz.innerHTML ="some text"

None of the above approach works.

When i use approach 1 in other functions of A.js(non callback functions) it works fine.

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

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

发布评论

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

评论(1

临风闻羌笛 2024-10-15 18:47:18

您无法在模板中对小部件的 ID 进行硬编码。 id 必须唯一地标识小部件类型的实例,因此必须在创建时给出。

例如,您可以在 js: 中以编程方式执行类似操作,

var myA = new myWidgets.A({});
myA.startup();
myA.xyz.innerHTML = "some text"

或在 html:

<div data-dojo-type="myWidgets.A" data-dojo-props="id:'myA'"></div>

和 js 中以声明方式执行以下操作:

dijit.byId("myA").xyz.innerHTML = "some text";

You cannot hardcode the id of a widget in it's template. The id has to identify an instance of a widget-type uniquely, so it has to be given on creation.

You can for example do something like, programmatic in js:

var myA = new myWidgets.A({});
myA.startup();
myA.xyz.innerHTML = "some text"

or declaratively in html:

<div data-dojo-type="myWidgets.A" data-dojo-props="id:'myA'"></div>

and js:

dijit.byId("myA").xyz.innerHTML = "some text";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文