modifying text of a div using dojo

半世苍凉 提交于 2019-12-14 02:07:11

问题


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.


回答1:


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";


来源:https://stackoverflow.com/questions/4499221/modifying-text-of-a-div-using-dojo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!