javascript - 使用 ExtJS 单击按钮时更新区域

标签 javascript dom extjs extjs4

抱歉我是新手,我虽然这很容易做到,但我认为我不了解 ExtJS 的基础知识:(。

我的目标:我有一个包含三个容器的页面。 中间的容器首先是空白的。 当您单击某个按钮时,我希望将中间的容器更改为另一个容器。

为此,我做到了: 第一个“空白”容器:

var centerregion = Ext.create('Ext.container.Container', { 
border: false,
collapsible: false,
xtype: 'container',
id: 'centerregion',
items: [
    {
    border: true,
    xtype: 'window',
    visible: true,
    }, 
]
});

当您点击时我希望显示的容器:

var consultation = Ext.create('Ext.container.Container', { 
border: false,
collapsible: false,
xtype: 'container',
id: 'consultation',
items: [
    {
    border: true,
    xtype: 'image',
    src: '/bundles/app/images/clouds.png',
    }, 
]
}); 

然后是按钮上的监听器:

listeners: {
click: function(){
    Ext.getCmp('centerregion').update('consultation');
}
},

当我点击时,它正在“工作”,中心区域发生变化,但新区域仅显示文本“咨询”。 显然,

 Ext.getCmp('centerregion').update('bob');

当 update() 正在等待 html 代码时,将显示一个显示文本“bob”的区域。

无论如何,我认为这不是更新区域的正确方法。 也许我应该只有一个容器,并更新它的内容而不是调用另一个容器? 如果有人有任何提示:-)!

编辑:我的页面是这样构造的:

Ext.onReady(function() {
var mainscreen;
mainscreen = Ext.create('Ext.container.Viewport', {
    layout:'border',      
    items: [
        {
        layout: 'anchor',
        region: 'center',
        items: [
        maintopmenu,
        centerregion,
        ],
        },
        footer,
    ]
});

最佳答案

只需将组件添加到容器中,如下所示:

centerregion.add(consultation);

编辑:

var container = mainscreen.down('container');//the item without xtype in your case
container.remove(centerregion);
container.insert(1,consultation)

关于javascript - 使用 ExtJS 单击按钮时更新区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20491194/

相关文章:

javascript - AngularJS - ng-show 和 ng-click 不起作用

javascript - 正则表达式范围如何与简写语法一起使用?

html - 如何将样式应用于超越其他元素边界的一段文本?

javascript - javascript 中的无效参数错误

javascript - 在 HTML5 Canvas 中创建粒子以遵循圆形路径

javascript - 将 json 数据中的文本显示到我的 html 文本框中

javascript - CSS,Js文件未加载,有时显示空白页面

javascript - 在 DOM 上移动输入时将光标保持在 html 输入中

javascript - ExtJS 操作 propertygrid 源信息

php - ExtJS Store 代理错误地使用 extraParams 中的数组构建 GET 请求