我正在尝试将新的AccordionPane添加到现有容器中,但对于我的生活,我无法让它工作。
有人能够建议我哪里出错吗?
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js" djConfig="parseOnLoad: true"> </script>
<script type="text/javascript">
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.layout.AccordionContainer");
</script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.4.0/dijit/themes/tundra/tundra.css">
<script type="text/javascript">
function AddNewPane() {
var accordPane = new dijit.layout.AccordionPane({"title": "test", "content":"hello"});
dijit.layout.AccordionContainer("myacc").addChild(accordPane);
accordPane.startup();
//select the new Pane
accordPane.selected = true;
}
</script>
</head>
<body>
<button type="button" onclick="AddNewPane();" >Add</button>
<div dojoType="dijit.layout.AccordionContainer" id="myacc" class="tundra" >
<div dojoType="dijit.layout.AccordionPane" title="Origional Acc 1" >
Testing One
</div>
<div dojoType="dijit.layout.AccordionPane" title="Origional Acc 2" >
Testing Two
</div>
</div>
<script>
document.getElementById("myacc").style.width = '200px';
document.getElementById("myacc").style.height = '200px';
</script>
</body>
</html>
答案 0 :(得分:2)
让它工作,谢谢。
function Testing() {
var accordion = dijit.byId("myacc");
var d = new dijit.layout.AccordionPane({id:'newpane', title:'hello', content: 'testing'});
accordion.addChild(d, 0);
dijit.byId('myacc').selectChild(dijit.byId('newpane'));
}
答案 1 :(得分:2)
作为original poster said,要将新的AccordionPane添加到AccordionContainer的 TOP ,请使用0作为 insertIndex 。 如果你想将新的AccordionPanel添加到AccordionContainer的 BOTTOM ,只需从.addChild中删除 insertIndex ,如下所示:
function Testing() {
var accordion = dijit.byId("myacc");
var d = new dijit.layout.AccordionPane({id:'newpane', title:'hello', content: 'testing'});
accordion.addChild(d);
accordion.selectChild(dijit.byId('newpane'));
}
另外,在我的情况下,我想要在AccordionContainer中添加一个新的AccordionPane,其内容从同一服务器上的另一个页面加载。以下代码适用于将来发现此想要做同样事情的人:
function Testing() {
var accordion = dijit.byId("myacc");
var d = new dijit.layout.AccordionPane({id:'newpane', title:'hello', href: "location/of/page.php", preload: true});
accordion.addChild(d);
accordion.selectChild(dijit.byId('newpane'));
}
此外,如果您想在选择孩子时启用动画,请将 true 添加到 animate 属性中:
accordion.selectChild(dijit.byId('newpane'), true);