ExtJS 视图创建

ExtJS View creation

本文关键字:创建 视图 ExtJS      更新时间:2023-09-26

我有以下看法:

Ext.define("FI.view.InstallBaseList", {
extend: 'Ext.grid.Panel',
require: 'FI.store.InstallBaseStore',
title: 'List',
alias: 'widget.installBaseList',
icon:'table.png',
store:'FI.store.InstallBaseStore',
columns: [],
divId:'',
    dockedItems: [],
height: 200,
width: 700,
renderTo: "container",
enableLocking: true,
draggable: true,
resizable: true,
 initComponent: function(config){
         console.log("here");
    }
});

这就是我尝试从控制器创建它的方式:

list = Ext.widget('installBaseList', params);

在浏览器中,我收到此错误:

me.dockedItems.insert is not a function
addDocked(items=[Object { xtype="header", title="List", titleAlign="left", more...}], pos=0)    ext-all-debug.js (line 47051)
updateHeader(force=undefined)    ext-all-debug.js (line 90398)
beforeRender()    ext-all-debug.js (line 90275)
getRenderTree()    ext-all-debug.js (line 26056)
render(container=Object { dom=div#container, id="container", $cache={...}, more...}, position=undefined)    ext-all-debug.js (line 26193)
constructor(config=Object { divId="container", columns=[0]})    ext-all-debug.js (line 44380)
callParent(args=[Object { divId="container", columns=[0]}])    ext-all-debug.js (line 3728)
constructor(config=Object { divId="container", columns=[0]})    ext-all-debug.js (line 56387)
constructor ()    ext-all-debug.js (line 3892)
widget(name="installBaseList", config=Object { divId="container", columns=[0]})    ext-all-debug.js (line 5083)
(?)()    ListCo...5323863 (line 98)

me.dockedItems.insert(pos + i, item);    ext-all-debug.js (line 47051)

更重要的是,在initComponent方法中,config似乎是未定义的。为什么?

问题出在哪里?

initComponent 方法必须包含对 callParent 的调用,以确保父类的 initComponent 方法也被调用。

这是修复 http://jsfiddle.net/nscrob/EcX3Q/11/

此外,您不需要将参数配置发送到 initComponent,对象配置已经分配给组件,可以通过它访问。因此,如果您有:Ext.create('...',{mode:add});在 init 组件中,您将拥有 this.mode = add;