我通常是这样写的,感觉还好。
<script type="text/javascript">
//1.组件继承:命名空间——>重写属性——>注册组件
Ext.ns("your.name");
your.name.newComponentName = Ext.extend(Ext.form.ComboBox,{
//需要默认的值,可以被覆盖
displayField: 'yearName',
valueField: 'yearCode',
emptyText: '请选择..',
mode: 'remote',
editable: false,
selectOnfocus: true,
triggerAction: 'all',
store: new Ext.data.JsonStore({
url: '',
fields: new Ext.data.Record.create([]),
root: 'root',
autoLoad: true
})
});
//注册后 可以用xtype: '简称'来创建该组件
Ext.reg('简称',your.name.newComponentName);
</script>
<script type="text/javascript">
//2.写一个完整页面的套路: 命名空间——>主要代码——>执行代码
Ext.ns("your.name");
your.name.newComponent = function() {
//可以定义变量
var a;
var b;
//没有: 代码都在里面
return {
//最后init会被执行
init : function() {
//调用其它方法 方法名要加上前面的your.name.newComponent
//要有组件的引用要注意先后顺序!
your.name.newComponent.doPanel01();
your.name.newComponent.doPanel02();
your.name.newComponent.function01();
your.name.newComponent.functino02();
},
doPanel01 : function() {
},
doPanel02 : function() {
},
function01 : function() {
},
function02 : funciton() {
}
}
}();
Ext.onReady(your.name.newComponent.init,your.name.newComponent);
</script>