用于在dojo TabContainer中添加附加选项卡的按钮

时间:2015-07-06 18:45:06

标签: javascript dojo

基本上我有一个JSP页面,在单击按钮时,它应该创建一个新的选项卡,其中href设置为$ {submission.id}变量。但是,单击该按钮不会生成任何选项卡。我已经尝试过查看dojo教程和阅读文档,但我对自己的错误感到迷茫。

<script>
dojoConfig = {
    async : true,
    parseOnLoad : true
}
</script>
<script src="js/dojo/dojo.js"></script>
<div id="tabPanel" data-dojo-type="dijit/layout/TabContainer" style="width: 100%; height: 100%;" data-dojo-props="region: 'center'">
<div data-dojo-type="dijit/layout/ContentPane" title="Home" data-dojo-props="selected: true">
<button data-dojo-type="dijit/form/Button" type="button"
onclick="registry.byId('tabPanel').addChild(new ContentPane({
title:'test',
closable:true,
href:'submissions/${submission.id}'
}), 6);">Details</button>
</div>
</div>
<script>
require([ //Layout and Menu
         "dojo/parser",
         "dojo/dom",
         "dijit/layout/BorderContainer",
         "dijit/layout/ContentPane",
         "dijit/layout/TabContainer",
         "dijit/form/Button",
         "dojo/domReady!"
         ], function(parser) {
            parser.parse();
});
</script>

2 个答案:

答案 0 :(得分:0)

您的网页似乎没有一个ID为tabPanel的小部件。您的TabContainer具有 tabPanel,但您需要为tabPanel调用设置 id registry.byId找到它。

答案 1 :(得分:0)

onclick属性中调用的代码没有对所需模块的引用。 您可以尝试以下方法。

<button data-dojo-type="dijit/form/Button" type="button"
onclick="createTab();">Details</button>

<script>
function createTab(){
   require([ //registry and ContenPane
         "dijit/registry",
         "dijit/layout/ContentPane"
         ], function(registry,ContentPane) {

            registry.byId('tabPanel')
            .addChild(new ContentPane({
                 title:'test',
                 closable:true,
                 href:'submissions/${submission.id}'
              }),6);
    });
}
</script>