请看问题:
function newLayOutObj() {
var config = {
settings: {
"hasHeaders": true,
"constrainDragToContainer": false,
"reorderEnabled": false,
"selectionEnabled": false,
"popoutWholeStack": false,
"blockedPopoutsThrowError": false,
"closePopoutsOnUnload": false,
"showPopoutIcon": false,
"showMaximiseIcon": true,
"showCloseIcon": true,
"responsiveMode": "onload"
},
content: [{
type: 'column',
content: [{
type: 'component',
"reorderEnabled": false,
"hasHeaders": false,
"isClosable": false,
"showPopoutIcon": false,
"showMaximiseIcon": false,
"showCloseIcon": false,
componentName: 'parrent',
componentState: {
text: 'Component 1',
id: "4587645"
}
}
]
}]
};
return config;
};
function add() {
var newItemConfig = {
type: 'component',
componentName: 'parrent',
width: 38.197,
};
layout.root.contentItems[0].addChild(newItemConfig);
};
layOutObj = new newLayOutObj();
layout = new GoldenLayout(layOutObj);
layout.container = "#golden";
layout.registerComponent('parrent', function (container, state) {
container.getElement().html(`<h2 class="cname" >Component </h2>`);
});
layout.init();
$(function(){
$('#add').click(function(){ add(); })
})
body{ padding: 0px; background: #DDD; margin: 0px;}
.cname{ color:#FFF; text-align:center}
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="//golden-layout.com/files/latest/js/goldenlayout.min.js"></script>
<link type="text/css" rel="stylesheet" href="//golden-layout.com/files/latest/css/goldenlayout-base.css" />
<link type="text/css" rel="stylesheet" href="//golden-layout.com/files/latest/css/goldenlayout-dark-theme.css" />
<div id="ss" style="width: 800px; height:30px; margin:5px auto"> <button id="add"> Add </button> </div>
<div id="golden" style="width: 800px; height:280px; margin:0px auto"> </div>
我可以通过单击添加按钮来添加新行。一旦我关闭所有新添加的行,然后使用添加按钮重试,它将模式更改为嵌套列,我希望它作为行谢谢
var newItemConfig = {
type: 'component',
componentName: 'parrent',
width: 38.197,
};
layout.root.contentItems[0].addChild(newItemConfig);
我正在使用这种方法添加新项目