开发者

Problem with using dojoAttachpoint while adding /removing style

开发者 https://www.devze.com 2023-02-18 22:47 出处:网络
I have a div as show below: <div id=\"xyz\"开发者_如何学运维 dojoAttachPoint=\"xyz\" style=\"display: none;\"></div>

I have a div as show below:

<div id="xyz"开发者_如何学运维 dojoAttachPoint="xyz" style="display: none;">  </div>

Now I want to show/ hide it. If I do it using dojo.byID it works. But if I do it using dojoAttachppoint it does not work properly. I don't get any errors but changes don't take place.

dojo.byId("xyz").style.display="none";
dojo.byId("xyz").style.display="";


this.xyz.style.display ="none";
this.xyz.style.display ="";

What can be the problem?


Are you using the above in a template within a class declared using dojo.declare with base class dijit._Templated?

Your understanding of attach points is flaky. When dijit._Templated parses the tenmplate, and when it sees a "dojoAttachPoint" attribute, it will create a property in the dijit object with the attach point's name. Therefore, "xyz" is a property in the dijit class object. The name is taken from the attribute called "dojoAttachPoint" when the template is being read. The dojoAttachPoint attribute is no longer used afterwards.

If "this" points to the dijit class you created, this.xyz will point to the DOM element (i.e. the div), never a widget. Therefore it does not have a "domNode" property. Trace the source code in dijit/_Templated.js line#191 to confirm.

Therefore, you need to do some console.log calls to confirm that this.xyz is returning the correct div. If it does, then you can try dojo.style(this.xyz, "display", "none") to see if you can hide it etc.

As to why this.xyz.style.display = "none" won't work, it may be a browser-specific thing, as it should do the same thing as dojo.style. You'll need to dig deeper to find out.

0

精彩评论

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