ExtJS 持久面板(无 autoDestroy)
亲爱的程序员朋友们晚上好!
我有一个关于 ExtJS 中持久面板的问题。我有一些表单面板,我想将它们显示在单个容器面板内。显示的形式取决于用户正在编辑的对象的类型。据我了解,这可以通过以下3条语句来实现:
- removeAll(true)
- add(persistent form panel)
- doLayout()
问题是这似乎不起作用。如果使用 2 个不同的持久表单面板,它们都会粘在容器面板上。奇怪的是,当我不使用持久面板时,它似乎确实有效,但每次将表单面板添加到容器时都重新创建表单面板:
- removeAll(true)
- add(new form panel())
- doLayout()
请参阅下面的工作示例:
<script type="text/javascript" language="javascript">
Ext.namespace("Ext.ARA");
Ext.onReady(function()
{
Ext.ARA.AddFormPanelDoesntWorkA = function()
{
Ext.ARA.ContainerPanel.removeAll(false);
Ext.ARA.ContainerPanel.add(Ext.ARA.FormPanelA);
Ext.ARA.ContainerPanel.doLayout();
}
Ext.ARA.AddFormPanelDoesntWorkB = function()
{
Ext.ARA.ContainerPanel.removeAll(false);
Ext.ARA.ContainerPanel.add(Ext.ARA.FormPanelB);
Ext.ARA.ContainerPanel.doLayout();
}
Ext.ARA.AddFormPanelDoesWorkA = function()
{
Ext.ARA.ContainerPanel.removeAll(true);
Ext.ARA.ContainerPanel.add(new Ext.form.FormPanel({title:'Form Panel A', padding:5, items:[new Ext.form.TextField({fieldLabel:'Panel A Field', anchor:'100%'})]}));
Ext.ARA.ContainerPanel.doLayout();
}
Ext.ARA.AddFormPanelDoesWorkB = function()
{
Ext.ARA.ContainerPanel.removeAll(true);
Ext.ARA.ContainerPanel.add(new Ext.form.FormPanel({title:'Form Panel B', padding:5, items:[new Ext.form.TextField({fieldLabel:'Panel B Field', anchor:'100%'})]}));
Ext.ARA.ContainerPanel.doLayout();
}
Ext.ARA.FormPanelA = new Ext.form.FormPanel({title:'Form Panel A', padding:5, items:[new Ext.form.TextField({fieldLabel:'Panel A Field', anchor:'100%'})]});
Ext.ARA.FormPanelB = new Ext.form.FormPanel({title:'Form Panel B', padding:5, items:[new Ext.form.TextField({fieldLabel:'Panel B Field', anchor:'100%'})]});
Ext.ARA.ContainerPanel = new Ext.Panel
({
title:'Container Panel',
bbar:new Ext.Toolbar
({
items:
[
{text:'AddFormPanelDoesntWorkA', handler:Ext.ARA.AddFormPanelDoesntWorkA},
{text:'AddFormPanelDoesntWorkB', handler:Ext.ARA.AddFormPanelDoesntWorkB}, '->',
{text:'AddFormPanelDoesWorkA', handler:Ext.ARA.AddFormPanelDoesWorkA},
{text:'AddFormPanelDoesWorkB', handler:Ext.ARA.AddFormPanelDoesWorkB}
]
})
});
Ext.ARA.Mainframe = new Ext.Viewport({layout:'fit', items:[Ext.ARA.ContainerPanel]});
});
</script>
在 ExtJS 中使用持久表单面板的正确方法是什么?我在这里做错了什么?
Good evening dear fellow programmers!
I have a question regarding persistant panels in ExtJS. I have a few form panels that I want to display inside a single container panel. The displayed form depends on the type of object that the user is editing. As far as I understand, this can be achieved by the following 3 statements:
- removeAll(true)
- add(persistent form panel)
- doLayout()
The problem is that this doesn't seem to work. If using 2 different persistent form panels, they both stick to the container panel. The strange thing is that it does seem to work when I don't use persistent panels, but recreate the form panels every time I add them to the container:
- removeAll(true)
- add(new form panel())
- doLayout()
See a working example below:
<script type="text/javascript" language="javascript">
Ext.namespace("Ext.ARA");
Ext.onReady(function()
{
Ext.ARA.AddFormPanelDoesntWorkA = function()
{
Ext.ARA.ContainerPanel.removeAll(false);
Ext.ARA.ContainerPanel.add(Ext.ARA.FormPanelA);
Ext.ARA.ContainerPanel.doLayout();
}
Ext.ARA.AddFormPanelDoesntWorkB = function()
{
Ext.ARA.ContainerPanel.removeAll(false);
Ext.ARA.ContainerPanel.add(Ext.ARA.FormPanelB);
Ext.ARA.ContainerPanel.doLayout();
}
Ext.ARA.AddFormPanelDoesWorkA = function()
{
Ext.ARA.ContainerPanel.removeAll(true);
Ext.ARA.ContainerPanel.add(new Ext.form.FormPanel({title:'Form Panel A', padding:5, items:[new Ext.form.TextField({fieldLabel:'Panel A Field', anchor:'100%'})]}));
Ext.ARA.ContainerPanel.doLayout();
}
Ext.ARA.AddFormPanelDoesWorkB = function()
{
Ext.ARA.ContainerPanel.removeAll(true);
Ext.ARA.ContainerPanel.add(new Ext.form.FormPanel({title:'Form Panel B', padding:5, items:[new Ext.form.TextField({fieldLabel:'Panel B Field', anchor:'100%'})]}));
Ext.ARA.ContainerPanel.doLayout();
}
Ext.ARA.FormPanelA = new Ext.form.FormPanel({title:'Form Panel A', padding:5, items:[new Ext.form.TextField({fieldLabel:'Panel A Field', anchor:'100%'})]});
Ext.ARA.FormPanelB = new Ext.form.FormPanel({title:'Form Panel B', padding:5, items:[new Ext.form.TextField({fieldLabel:'Panel B Field', anchor:'100%'})]});
Ext.ARA.ContainerPanel = new Ext.Panel
({
title:'Container Panel',
bbar:new Ext.Toolbar
({
items:
[
{text:'AddFormPanelDoesntWorkA', handler:Ext.ARA.AddFormPanelDoesntWorkA},
{text:'AddFormPanelDoesntWorkB', handler:Ext.ARA.AddFormPanelDoesntWorkB}, '->',
{text:'AddFormPanelDoesWorkA', handler:Ext.ARA.AddFormPanelDoesWorkA},
{text:'AddFormPanelDoesWorkB', handler:Ext.ARA.AddFormPanelDoesWorkB}
]
})
});
Ext.ARA.Mainframe = new Ext.Viewport({layout:'fit', items:[Ext.ARA.ContainerPanel]});
});
</script>
What is the proper way to use persistent form panels in ExtJS? What am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试了你的示例并做了一些调整,但没有让它工作,然后我意识到我会使用 CardLayout 用于这种显示。请参阅 LayoutBrowser,其中使用“向导”类型的显示。我想它会给你你所需要的。
I tried your example and made a few tweaks and didn't get it to work and then I realised that I'd have used a CardLayout for this sort of display. See the LayoutBrowser where it is demonstrated using a 'Wizard' type of display. I think it'll give you what you need.