Ext.Panel.tbar上的“布局运行失败”

时间:2013-11-27 11:54:33

标签: javascript extjs

我是extjs 4.0的新学习者,并尝试了一些学习材料的例子。 使用以下代码“布局运行失败”时,一个示例无法正常工作:

var panel = Ext.create("Ext.Panel",{
    renderTo:Ext.getBody(),
    layout:"auto",
    height:500,
    width:400,
    autoLoad:{
        url:"Component.txt",
        renderer:"component"
    },
    renderer:"component",
    tbar:[
        {text:"load", scope:panel, handler:function() {
                panel.loader.load({
                    url:"Component1.txt",
                    renderer:"component"
                });
            }
        },
        {text:"remove", scope:panel, handler:function() {
                panel.loader.load({
                    url:"Component1.txt",
                    renderer:"component",
                    removeAll:true
                });
            }
        }
    ]
});

component.txt:
{xtype:'panel',height:100, width:200, html:"Original Component"}

component1.txt:
{xtype:'panel', height:100, width:90, html:"New Component"}

我尝试删除tbar部分,但它确实有效。 所以我认为问题出在tbar。 Ext JS版本:ext-4.2.1.883 浏览器:Firefox 25.0.1,谷歌浏览器31.0.1650.57米

有什么好的建议吗?

1 个答案:

答案 0 :(得分:0)

scope: panel存在问题。您不能在该变量的定义中使用变量panel。你的代码说:

panel = Ext.create( .... scope: panel ...);

这没有任何意义。也许scope: this会做你想要的。如果没有,你必须重新思考你定义班级的方式。

无论如何,建议的方法是在专用文件中定义您的类,并坚持MVC recommendations