Dojo使用domConstruct将声明性代码添加到现有的手风琴中

时间:2013-10-03 20:22:48

标签: javascript dojo accordion tabcontainer

我有一支手风琴,以编程方式添加了内容窗格。在其中一个窗格中,我想添加一个包含许多选项卡的选项卡容器。每个选项卡都有许多需要动态创建的控件。但创造它动态的方式给我带来了困难。我决定采用不同的方法使用domConstruct.place添加它。我有完成声明方式的代码设计,并在每个选项卡的单独html页面中。然后我尝试将整个选项卡容器作为子项添加到现有的accordion的内容窗格中。

屏幕上只显示文字内容,但没有标签容器控件。

以下是代码:

require(["dgrid/OnDemandGrid", "dijit/layout/ContentPane", "dijit/layout/AccordionContainer", "dijit/layout/TabContainer", "dijit/form/Button", "dgrid/Selection", 
            "dgrid/Keyboard", "dojo/_base/declare", "dojo/store/JsonRest", "dojo/store/Observable", "dojo/store/Memory", "dijit/registry", "dgrid/extensions/DijitRegistry", 
            "dgrid/extensions/Pagination", "dgrid/extensions/CompoundColumns", "dgrid/extensions/ColumnResizer", "dojo/dom-construct", "dojo/text!../App/tab.html", "dojo/domReady!"],
                function(Grid, ContentPane, AccordionContainer, TabContainer, Button, Selection,
                        Keyboard, declare, JsonRest, Observable, Memory, registry, DigitRegistry, 
                        Pagination, CompoundColumns, ColumnResizer, domConstruct, tabHtml){

                    var aContainer = registry.byId('accord');

                    if (!aContainer) {
                        console.log('Accordion does not exist');
                        aContainer = new AccordionContainer({style:"width: auto; height: 680px;"}, "accord");
                    }

//Grid creation part goes here. Grid appears and events works.

var cpid = "acordcp1_tc_cp1_" + getRandomNumber();
var cp1 = new ContentPane({id: cpid, title: "pane1", content: grid});

aContainer.addChild(cp1);
aContainer.startup();
aContainer.selectChild(cp1);
aContainer.resize();

console.log("TAB HTML", tabHtml);
var tb1 = domConstruct.create("div", {innerHTML: tabHtml}, cpid, "first");

}

//这是来自dojotoolkit教程的示例选项卡容器声明性代码,我试图在accordion的内容窗格中获取它。

<div data-dojo-type="dijit/layout/TabContainer" style="width: 100%; height: 100%;">
    <div data-dojo-type="dijit/layout/ContentPane" title="My first tab" data-dojo-props="selected:true">
        Lorem ipsum and all around...
    </div>
    <div data-dojo-type="dijit/layout/ContentPane" title="My second tab">
        Lorem ipsum and all around - second...
    </div>
    <div data-dojo-type="dijit/layout/ContentPane" title="My last tab" data-dojo-props="closable:true">
        Lorem ipsum and all around - last...
    </div>
</div>

但我得到的是:

Lorem ipsum和周围...... Lorem ipsum和周围 - 第二...... Lorem ipsum和周围 - 最后......

是的,只有文本会出现在手风琴的内容窗格中以及网格控件上。

我的dojo配置也是:

<script type="text/javascript"
    djconfig="isDebug: true, parseOnLoad: true" src="dojo/dojo/dojo.js"></script>

我做错了什么?

这种方法不正确吗?有什么建议?

我真的很感激帮助。感谢。

拉​​姆

1 个答案:

答案 0 :(得分:1)

dojo解析器将您的标记转换为dojo小部件和dijit。它在加载页面时运行一次。将标记添加到页面后,您需要在标记上运行它。你有两个选择。

  1. 等待运行解析器。在配置中将parseOnLoad设置为false,然后在添加标记后在代码中调用parser.parse()。

  2. 在新div上再次运行解析器。

    parser.parse(tb1)

  3. 如果您需要首先显示其他声明性代码,则第二种方法是必要的。