gpt4 book ai didi

javascript - Dojo stackContainer 在调整窗口大小之前不显示子项

转载 作者:行者123 更新时间:2023-11-30 18:12:02 25 4
gpt4 key购买 nike

这是我要创建的小部件。目标是让一个 stackContainer 由顶部的单选按钮控制。

我已经尝试过 dojo 文档中的示例,但它具有相同的错误行为。

define(["dojo/ready",  "dojo/_base/declare", "dijit/_WidgetBase", "dojo/dom-construct", 
"dojo/_base/lang", "dojo/on", "dojo/dom-attr", "dijit/form/RadioButton",
"dojo/dom-style", "dijit/layout/ContentPane", "dijit/layout/StackContainer",
"tcs/Log"],
function(ready, declare, _WidgetBase, domConstruct,
lang, on, attr, RadioButton,
style, ContentPane, StackContainer,
log) {

/**
* @class
* @name gijit.workflow.debug.combi
*/
return declare("gijit.workflow.debug.combi", [_WidgetBase], {
workflow : null,
panes : null,
width : "600px",
height : "400px",

_beforeCall : function(d) {
alert("beforeCall");
},

buildRendering : function() {
this.domNode = domConstruct.create("div", {id:"myform"});
var contain = domConstruct.create("div", null, this.domNode, "last");
var stackContainer = new StackContainer({
style: "height: " + this.height + "; width: " + this.width + "; border: 0px solid red"
}, contain);
var buttons = domConstruct.create("form", null, this.domNode, "first");
for(var i=0; i<this.panes.length; i++){
var contentPane = new ContentPane({
id : this.panes[i].title,
title : this.panes[i].title,
content : this.panes[i].content
})
stackContainer.addChild(contentPane);

var buttonDiv = domConstruct.create("span", null, buttons, "last");
style.set(buttonDiv, "display", "inline-block");
style.set(buttonDiv, "margin", "10px");

var label = domConstruct.create("div", {innerHTML: this.panes[i].title}, buttonDiv, "last");

if(i==0){
var RButton = new RadioButton({
title : this.panes[i].title,
showTitle : true,
checked : true,
value : this.panes[i].title,
name : "options",
onClick : function(a){stackContainer.selectChild(a.explicitOriginalTarget.attributes.value.textContent)}
}).placeAt(buttonDiv);
} else {
var RButton = new RadioButton({
title : this.panes[i].title,
showTitle : true,
checked : false,
value : this.panes[i].title,
name : "options",
onClick : function(a){stackContainer.selectChild(a.explicitOriginalTarget.attributes.value.textContent)}
}).placeAt(buttonDiv);
}
contentPane.resize();
contentPane.startup();
}
stackContainer.startup();
//Hacks in attempt to get the stuff to show
for(var i=0; i<stackContainer.getChildren().length; i++){
stackContainer.getChildren()[i].startup();
stackContainer.getChildren()[i].resize();
if(typeof stackContainer.getChildren()[i].getChildren()[0] === 'object'){
stackContainer.getChildren()[i].getChildren()[0].startup();
}
}
stackContainer.resize();
},
});
});

在大多数情况下,它是有效的。但是为了显示任何内容,我必须调整窗口大小。所有大小调整/启动调用都是在最初不起作用后添加的,但它们都没有做任何事情。

最佳答案

如果您以编程方式将子窗口小部件添加到您的窗口小部件,您需要定义一个启动子窗口小部件的启动函数。每当创建新实例并将其放置在 dom 中时,都应调用该启动函数。例如:

require(["dojo/ready", "dojo/_base/declare", "dijit/_WidgetBase", "dojo/dom-construct",
"dojo/_base/lang", "dojo/on", "dojo/dom-attr", "dijit/form/RadioButton",
"dojo/dom-style", "dijit/layout/ContentPane", "dijit/layout/StackContainer"],

function (ready, declare, _WidgetBase, domConstruct,
lang, on, attr, RadioButton,
style, ContentPane, StackContainer) {


var MyClass = declare("gijit.workflow.debug.combi", [_WidgetBase], {
startup: function () {
this.inherited(arguments);
stackContainer.startup();
}
});
var x = new MyClass({});
x.placeAt('node');
//manually call startup after instantiating the widget. If the parser is what is creating your widget, it calls startup automatically. startup must be called after the widget is in the dom.
x.startup();
console.log(x);
});

关于javascript - Dojo stackContainer 在调整窗口大小之前不显示子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14346998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com