0

我是 dojo 的新手,但不是 JavaScript 的新手。

我正在测试功能并尝试构建一个基本的 dijit.layout.StackContainer(以声明方式和编程方式)。我所拥有的是我的堆栈容器的大小是根据第一个子元素的大小来确定的。我想要的是根据我放置它的元素的大小来调整它的大小。我怎样才能做到这一点?我查看了参考指南、API 文档等,但似乎没有任何帮助。:(

提前致谢

我能够让它工作的唯一方法是,如果我在希望附加我的 StackContainer 的元素上定义 height 属性,然后在声明 StackContainer 的 style 属性时手动查找 height 属性。像这样...

<div id="content" style="height: 100%; background-color: green;"></div>
<script>
    var domNode, controller, container;
    domNode = document.getElementById('content');
    controller = new StackController({
        containerId:"mainStack"
    }).placeAt(domNode);
    container = new StackContainer({
        id: "mainStack",
        isLayoutContainer: true,
        style: "background-color: yellow; height: "+domNode.style.height
    });
    container.addChild(new ContentPane({
        title: "Search for Images...",
        tooltip: "Click here to begin your search.",
        content: searchTemplate
    }));
    container.addChild(new ContentPane({
        title: "View Results..",
        tooltip: "After you search for a topic, click here to view your results.",
        content: resultTemplate
    }));
    container.placeAt(domNode);

    container.startup();
    controller.startup();
</script>

这行得通,但由于缺乏使用道场的经验,我感觉就像是一个黑客。有没有人有任何想法或建议?

4

1 回答 1

0

您想将doLayoutStackContainer 上的属性设置为 false。根据文档

doLayout
Defined by dijit/layout/StackContainer
If true, change the size of my currently displayed child to match my size

这相当于

container = new StackContainer({
   id: "mainStack",
   isLayoutContainer: true,
   style: "background-color: yellow;",
   doLayout:false
});

你可能还需要doLayout:false对孩子。

于 2012-10-03T12:14:07.400 回答