问题描述
我正在尝试打开 &以编程方式关闭手风琴窗格.这是我的代码的简化版本.即使我将第一个窗格的选择设置为 false,将第二个窗格的选择设置为 true,但在浏览器 (FF3) 上加载时,只有第一个窗格会打开.
I am trying open & close accordion panes programatically. Here is the simplified version of my code. Even though I set the first pane's selected to false and and second pane's selected to true, only the first pane opens when it loads on the browser (FF3).
var accordionContainer = new dijit.layout.AccordionContainer().placeAt("test");
var accordPane = new dijit.layout.ContentPane({"title": "test", "content":"hello"});
var accordPane2 = new dijit.layout.ContentPane({"title": "test1", "content":"hello1"});
accordionContainer.addChild(accordPane);
accordionContainer.addChild(accordPane2, 1);
accordPane.startup();
accordPane2.startup();
//accordionContainer.selectChild(accordPane2);
accordionContainer.startup();
accordPane.selected = false;
accordPane2.selected = true;
推荐答案
你可以这样做:
accordionContainer.selectChild( accordPane2 );
假设您使用的是 dojo 1.3.
Assuming you are using dojo 1.3.
dijit.layout.AccordionContainer
是 dijit.layout.StackContainer
的子类,定义了 selectChild
.
dijit.layout.AccordionContainer
is a subclass of dijit.layout.StackContainer
, which has selectChild
defined.
我设置了一个演示页面,您可以在其中看到此代码的实际效果
如果您在 startup
之前调用 selectChild
,这可能会导致您看到的错误,因为小部件未处于完成"状态.(抱歉,在我发布原始答案之前错过了commneted 代码)
If you were calling selectChild
before startup
, that could cause the error you were seeing since the widget wasn't in a 'complete' state. (Sorry, missed the commneted out code before I posted original answer)
这篇关于在 Dijit AccordionContainer 中以编程方式打开窗格的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!