Extjs 5.0,动态地将项目添加到手风琴中
Extjs 5.0, add dynamically an item to an accordian
我想在添加项目时将动态项目添加到我的手风琴布局中,折叠按钮不起作用。
如果我直接添加项目 - 不是动态 - 它工作正常。 如果您有一个简单的示例如何做到这一点,我将不胜感激。下面是我的代码:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="framework/packages/ext-theme-gray/build/resources/ext-theme-gray-all.css">
<script type="text/javascript" src="framework/build/ext-all.js"></script>
<script type="text/javascript" src="framework/build/packages/ext-theme-gray/build/ext-theme-gray.js"></script>
</head>
<body>
<script >
Ext.onReady(function(){
var viewport = new Ext.Viewport({
layout: 'border',
renderTo: Ext.getBody(),
items: [
{
region: 'west',
id: 'west-panel', // see Ext.getCmp() below
layout: {
type: 'accordion',
titleCollapse: false,
animate: true,
activeOnTop: true
},
title: 'West',
split: true,
width: 300,
minWidth: 175,
maxWidth: 400,
collapsible: false,
animCollapse: false,
margins: '0 0 0 5',
items: [{id: 'generalParam' ,title: 'General Param' ,iconCls: 'nav' ,
dockedItems: [{xtype: 'toolbar',dock: 'left',margins: '5 5 5 5',
items: [
{xtype: 'button',text: 'Currency' ,iconCls:'chr'},
{xtype: 'button',text: 'Area' ,iconCls:''},
{xtype: 'button',text: 'Bank' ,iconCls:''},
{xtype: 'button',text: 'Network' ,iconCls:''},
{xtype: 'button',text: 'MCC' ,iconCls:''},
{xtype: 'button',text: 'Static Data',iconCls:''},
{xtype: 'button',text: 'Interfaces' ,iconCls:''},
{xtype: 'button',text: 'Sequences' ,iconCls:''},
{xtype: 'button',text: 'MCC' ,iconCls:''}
]}]
}
]
},
Ext.create('Ext.tab.Panel', {
region: 'center', // a center region is ALWAYS required for border layout
deferredRender: false,
items: [{
bodyStyle: 'background-image:url(images/square.gif)',
html: 'Internal notes go here',
title: 'Welcome',
closable: true,
autoScroll: true
}]
}), {
xtype: 'tabpanel',
autoShow:true,
region: 'east',
title: 'Information',
animCollapse: true,
collapsible: true,
split: true,
width: 275, // give east and west regions a width
minSize: 175,
maxSize: 400,
margins: '0 5 0 0',
activeTab: 1,
tabPosition: 'bottom',
items: [{
html: '<p>A TabPanel component can be a region.</p>',
title: 'A Tab',
autoScroll: true
}, Ext.create('Ext.grid.PropertyGrid', {
title: 'Property Grid',
closable: false,
source: {
"(name)": "Properties Form",
"grouping": false,
"autoFitColumns": true,
"productionQuality": false,
"created": Ext.Date.parse('10/15/2006', 'm/d/Y'),
"tested": false,
"version": 0.01,
"borderWidth": 1
}
})]
},
{
xtype:'panel',
region: 'south',
split: true,
height: 100,
minSize: 100,
maxSize: 200,
collapsible: true,
collapsed: true,
title: 'South',
margins: '10 10 10 10'
}
]
});
var item1 = {id: 'cardSetting' ,title: 'Card Settings' ,iconCls: 'settings'};
var item2 ={title: 'new item' ,iconCls: 'crv' };
Ext.getCmp('west-panel').add(item1);
Ext.getCmp('west-panel').add(item2);
Ext.getCmp('west-panel').doLayout();
});
</script>
</body>
</html>
我已经简化了您的代码,以便它更具体地针对该问题,在简化它的过程中,我无法再复制该问题。由于代码Ext.onReady
,我假设您使用 ExtJs 3。
当我第一次复制您的代码时,在选项卡面板的中间显示有关使用 Ext.create 的错误,所以我删除了面板,默认类型是面板,因此不需要这样做。
这是我目前正在测试的代码:
Ext.onReady(function () {
var viewport = new Ext.Viewport({
layout: 'border',
renderTo: Ext.getBody(),
items: [
{
region: 'west',
id: 'west-panel', // see Ext.getCmp() below
layout: {
type: 'accordion',
titleCollapse: false,
animate: true,
activeOnTop: true
},
title: 'West',
split: true,
width: 300,
minWidth: 175,
maxWidth: 400,
collapsible: false,
animCollapse: false,
margins: '0 0 0 5',
items: [{
id: 'generalParam',
title: 'General Param',
iconCls: 'nav',
html: '<p>Panel content!</p>'
}, {
id: 'cardSetting',
title: "Card Settings",
iconCls: "settings",
html: '<p>Panel content!</p>'
}]
},
{
region: 'center', // a center region is ALWAYS required for border layout
deferredRender: false,
items: [{
bodyStyle: 'background-image:url(images/square.gif)',
html: 'Internal notes go here',
title: 'Welcome',
closable: true,
autoScroll: true
}]
}
]
});
var item1 = {id: 'cardSetting2', title: 'Card Settings2', iconCls: 'settings', html: '<p>Panel content!</p>'};
var item2 = {title: 'new item 3', iconCls: 'crv', html: '<p>Panel content!</p>'};
Ext.getCmp('west-panel').add(item1);
Ext.getCmp('west-panel').add(item2);
Ext.getCmp('west-panel').doLayout();
});
您能否尝试此代码,看看是否仍然遇到问题,如果是,请提供详细信息,我将通过回复更新此答案。祝项目好运。
编辑:请参阅工作煎茶小提琴
我已经通过在渲染之前添加一个侦听器来解决这个问题,listeners: {beforerender:addAccordion}并定义一个函数 addAccordion,如下所示:
var addAccordion = function(){ var accordion_panel=Ext.getCmp('west-panel'); var item1 = {id: 'cardSetting' ,title: 'Card Settings' ,iconCls: 'settings'}; var item2 ={title: 'new item' ,iconCls: 'crv' }; accordion_panel.add(item1); accordion_panel.add(item2); };谢谢
- 在Javascript中,当使用array.prush方法向列表中添加项目时,如何对其进行排序
- 在不向上滚动的情况下向列表框中添加项目
- 为图像滑块jquery添加项目符号功能
- 在Javascript中使用JQueryMobile向列表添加项目
- ng只重复添加项目一次
- jCarousel-动态添加项目
- 如何在控制器对添加项目执行操作后更新视图
- SharePoint 2013 在添加项目上运行 Javascript
- 从选择框中删除项目或向选择框添加项目
- 如何在 ExtJS5 中网格编辑器组合的当前记录中添加项目
- 反应多个组件添加项目
- 如何在KeystoneJS中以编程方式从页面添加项目
- 正在添加项目id's到js-if语句
- Rails-如何在添加项目时强制刷新页面
- AngularJS+simpleCart问题显示购物车内容,直到添加项目
- 按$index添加项目的角度过滤器
- OwlCarousel 2.0.0-beta.2.4-可以预先添加项目,但不能使用'add.wowl.carou
- 允许使用向asp.net mvc4模型添加项目
- 在Javascript中按下按钮时向列表中添加项目
- contentflow通过函数添加项目