使用 dojo 修改 div 的文本
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在模板中对小部件的 ID 进行硬编码。 id 必须唯一地标识小部件类型的实例,因此必须在创建时给出。
例如,您可以在 js: 中以编程方式执行类似操作,
或在 html:
和 js 中以声明方式执行以下操作:
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:
or declaratively in html:
and js: