以编程方式打开 Dijit AccordionContainer 内的窗格的最佳方法是什么
我正在尝试打开& 以编程方式关闭折叠面板。 这是我的代码的简化版本。 即使我将第一个窗格的选择设置为 false,并将第二个窗格的选择设置为 true,但在浏览器 (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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以这样做:
假设你使用的是dojo 1.3。
dijit.layout.AccordionContainer
是dijit.layout.StackContainer
的子类,它定义了selectChild
。我设置了一个演示页面,您可以在其中看到此代码的实际运行
如果您正在调用
selectChild
在启动
之前,这可能会导致您看到的错误,因为小部件未处于“完整”状态。 (抱歉,在我发布原始答案之前错过了comnetout代码)You can do it like this:
Assuming you are using dojo 1.3.
dijit.layout.AccordionContainer
is a subclass ofdijit.layout.StackContainer
, which hasselectChild
defined.I set up a demo page where you can see this code in action
If you were calling
selectChild
beforestartup
, 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)