javascript - 可能的错误 - dijit/layout/ContentPane 在将小部件添加为子项时不会调整大小

标签 javascript dojo dijit.form

将小部件添加为子项时,小部件 dijit/layout/ContentPane 未正确调整大小。

重现问题的步骤:

  1. https://jsfiddle.net/9eja3jtr/ 打开测试用例
  2. 点击 10 次按钮“多次点击我!”。

问题:

  • dijit/layout/ContentPane 在将小部件添加为子项时不会调整大小。 插入的内容不完全可见。

我需要增加 dijit/layout/ContentPane 的尺寸以容纳新添加的小部件,以便所有内部小部件都应该可见。

我认为这是 dijit 小部件中的错误。如果有解决方法,我想知道。

注意事项: 我已经向 dojo 报告了错误 https://bugs.dojotoolkit.org/ticket/19021

require(["dijit/layout/ContentPane", "dijit/TitlePane", "dijit/form/Button", "dojo/domReady!"], function(ContentPane, TitlePane, Button) {
  this._contentPanel = new ContentPane({
    style: "background-color:red;"
  }, "contentPanel");

  this._titlePanel = new TitlePane({
    title: "I'm a TitlePane",
    content: "Collapse me!"
  }, "titlePanel");

  this._button = new Button({
    label: "Click me many times!",
    onClick: function() {
      this._titlePanel.addChild(new Button({
        label: "Test",
        style: "width: 250px"
      }));
    }.bind(this)
  }, "button");

  this._contentPanel.addChild(this._titlePanel);
  this._titlePanel.addChild(this._button);
  this._contentPanel.startup();
});

最佳答案

我认为解决此问题的最简单方法是用 BorderContainer 围绕您的 contentpane ,resize() 将自动触发,否则我认为您应该重新计算所有东西并调整所有封闭小部件的大小(不使用 BorderContainer)

下面是一个工作片段:(我已经指定了内容 Pane 的区域中心以防止错误)

require(["dijit/layout/BorderContainer","dijit/layout/ContentPane", "dijit/TitlePane", "dijit/form/Button", "dojo/domReady!"], function(BorderContainer,ContentPane, TitlePane, Button) {
  this._borderContainer = new BorderContainer({},"borderContainer");
  this._contentPanel = new ContentPane({
  	region: "center",
    style: "min-height:125px; background-color:red;"
  }, "contentPanel");

  this._titlePanel = new TitlePane({
    title: "I'm a TitlePane",
    content: "Collapse me!"
  }, "titlePanel");

  this._button = new Button({
    label: "Click me many times!",
    onClick: function() {
      this._titlePanel.addChild(new Button({
        label: "Test",
        style: "width: 200px"
      }));
      
    }.bind(this)
  }, "button");
	this._borderContainer.addChild(this._titlePanel);
  this._contentPanel.addChild(this._titlePanel);
  this._titlePanel.addChild(this._button);
  this._contentPanel.startup();
});
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link href="//ajax.googleapis.com/ajax/libs/dojo/1.10.0/dijit/themes/claro/claro.css" rel="stylesheet"/>
<div class="claro">
  <div id="borderContainer">
    <div id="contentPanel">
      <div id="titlePanel">
        <div id="button">
        </div>
        <div id="content">
        </div>
      </div>
    </div>
  </div>
</div>

关于javascript - 可能的错误 - dijit/layout/ContentPane 在将小部件添加为子项时不会调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43917164/

相关文章:

javascript - 更改必填字段中的弹出消息

javascript - 如何使用 html、css、javascript 和 php 和 mysql 作为后端为网站创建登录页面?

javascript - 在 typescript 中的 sammy js 中声明路由

javascript - CSS 工具提示不显示

javascript - 道场 dgrid : how style a single row?

css - 如何对齐 dijitTextbox 中的文本?

javascript - Dojo DateTextBox 不起作用

javascript - CSS 和 JavaScript 都没有使用 codeigniter 在移动 View 中加载?

javascript - 使用正则表达式验证电话号码不起作用

javascript - 如何获取 dijit/form/Form 中的输入?