开发者

modifying text of a div using dojo

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 w开发者_Python百科ant 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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜