How do I dynamically show and hide an entire TabCo

2020-03-02 02:14发布

DOJO seems to have some quirks here. I specifically need to have the TabContainer hidden when the page loads, but then become visible after the user clicks a button. The first thing I tried is setting style.display = "none" to start, and then setting style.display = "block" on the click event. Unfortunately, this only partially works- the page will render an invisible box in the right location/dimensions, but not render the actual contents. The box's contents only get rendered when triggered by something else (for example, going to a different FF tab or suspending/resuming firebug will make the box render).

If the style.display property is set to be visible on page load, everything works fine. You can toggle the display property and it shows or hides the tabcontainer properly. But if it's set to "none" on page load, it screws up.

I tried a workaround of setting the style.display property to "" in the HTML but then immediately setting it to "none" in the Javascript, but it still fails- the change occurs too soon and it needs to happen after the tabcontainer renders (which can take a second or two).

Some stripped sample code:

HTML:
<div id="tabContainer" dojoType="dijit.layout.TabContainer" style="width:500px; height:100px;display:none;">
</div>

and then the Javascript to show the tab on a user click:

function initTabs()  
{  
var tabContainer = dojo.byId('tabContainer');  
tabContainer.style.display = 'block';  
}  

How can I dynamically show/hide a TabContainer without having it start in the shown state?

9条回答
对你真心纯属浪费
2楼-- · 2020-03-02 02:46

After you set display:block do this:

dijit.byId('tabContainer').resize();

dijit.layout widgets often don't lay themselves out properly if they are display:none (and sometimes even when visibility:hidden). You have to fiddle around in Firebug till you figure out what works!

查看更多
虎瘦雄心在
3楼-- · 2020-03-02 02:50

There is solution for this. If you want to show TabContainer calll:

dijit.byId("tabContainer").domNode.style.display = 'block';
dijit.byId("tabContainer").resize();

and use 'none' if you want to hide TabContainer.

This works for me, but that is truth, it is not obvious :)

查看更多
不美不萌又怎样
4楼-- · 2020-03-02 02:58

Well, I did not solve this problem, but I came up with a workaround...Creating the TabContainer on the click event, instead of creating it hidden on page load and then showing it on the click event.

HTML:

<div id="tabContainer">     
</div>

JS:

var tabContainer = new dijit.layout.TabContainer({id:"tabContainer", style:"width:500px;height:200px;"}, dojo.byId('tabContainer'));  
//add tabs
tabContainer.startup();
查看更多
登录 后发表回答