lyon_fanfan 2009-12-16 13:35
浏览 267
已采纳

Ext 类继承的问题

我写了一个公共window类 主要作用是封装添加、修改员工的作用 已经实现 但是还有些小问题
1。如何声明内部变量
2。初始化数据如何该怎么写在类里面 而不需要外部调用才能初始化
代码如下:
[code="java"]
//用于智能提示显示
///
/*
人员编辑,添加公用页面类
*/
Ext.ux.EmployeeEditWindow = function(config){
//窗体隐藏属性 员工ID 新增为0
this.EmployeeEditWindow_ID = '-1';
//提交按钮的事件
this.EmployeeEidtWindow_SubmitFun = config.EmployeeEidtWindow_FunSubmit;
//窗口类型 'Add','Edit'
this.EmployeeEditWindow_WindowType = config.EmployeeEditWindow_WindosType;
//初始化数据
this.EmployeeEditWindow_InitData = config.EmployeeEditWindow_InitData;
//提交完毕后 需要刷新的storedata
this.EmployeeEditWindow_RefreshStore = config.EmployeeEditWindow_RefreshStore;

Ext.ux.EmployeeEditWindow.superclass.constructor.call(this,config);

}

Ext.extend(Ext.ux.EmployeeEditWindow,Ext.Window,{
labelSeparator : ': ',
buttonAlign : 'center',
plain: true,
resizable: false,
height: 220,
width: 600,
modal : true,
//************************************显示编辑页面<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
initFormPanel:function(){

//-->页面
var Employee_ShowEmployeeForm_OKButton = new Ext.Button({
name : 'Employee_ShowEmployeeForm_OKButton',
text : '提 交',
minWidth : 100

});
var Employee_ShowEmployeeForm_CancelButton = new Ext.Button({
name : 'Employee_ShowEmployeeForm_CancelButton',
text : '取 消',
minWidth : 100
});
var Employee_ShowEmployeeForm_CName = new Ext.form.TextField({
name : 'CName',
fieldLabel : '姓 名',
allowBlank : false,
width : 150
});
var Employee_ShowEmployeeForm_EName = new Ext.form.TextField({
name : 'EName',
fieldLabel : '英 文 名',
width : 150
});
var Employee_ShowEmployeeForm_Password = new Ext.form.TextField({
name : 'Password',
inputType : 'password',
fieldLabel : '密 码',
allowBlank : false,
width : 150
});
var Employee_ShowEmployeeForm_RepeatPassword = new Ext.form.TextField({
name : 'RepeatPassword',
inputType : 'password',
vtype:'password',
fieldLabel : '重复密码',
allowBlank : false,
width : 150,
vtype:'password',
vtypeText:"两次密码不一致!",
confirmTo:Employee_ShowEmployeeForm_Password.getId()
});
var Employee_ShowEmployeeForm_PhoneCall = new Ext.form.TextField({
name : 'PhoneCall',
fieldLabel : '座 机',
width : 150
});
var Employee_ShowEmployeeForm_MobileNo = new Ext.form.TextField({
name : 'MobileNo',
fieldLabel : '手 机',
width : 150
});
var Employee_ShowEmployeeForm_Birthday = new Ext.form.DateField({
name : 'Birthday',
fieldLabel : '生 日',
width : 150
});
var Employee_ShowEmployeeForm_Department = GetDepartmentTree('所属部门','DepartmentID');
var Employee_ShowEmployeeForm_Sex = GetDictionaryByCategoryID(1,'性 别',true,'SexID');
Employee_ShowEmployeeForm_Sex.width = 150;
var Employee_ShowEmployeeForm_Duty = GetDictionaryByCategoryID(5,'职 务',true,'DutyID');
Employee_ShowEmployeeForm_Duty.width = 150;

    return new Ext.form.FormPanel({
        name : 'Employee_ShowEmployeeForm_Panel',
        frame : true,
        border : false,
        labelAlgin:'right',
        modal : true,
        items : [
            {layout:'column',border:false,items:[
                    {columnWidth:.5,layout:'form',border:false,items:[
                        Employee_ShowEmployeeForm_CName
                    ]},
                    {columnWidth:.5,layout:'form',border:false,items:[
                        Employee_ShowEmployeeForm_EName
                    ]}                        
            ]},      
            {layout:'column',border:false,items:[
                    {columnWidth:.5,layout:'form',border:false,items:[
                        Employee_ShowEmployeeForm_Password
                    ]},
                    {columnWidth:.5,layout:'form',border:false,items:[
                        Employee_ShowEmployeeForm_RepeatPassword
                    ]}                        
              ]},
              {layout:'column',border:false,items:[
                    {columnWidth:.5,layout:'form',border:false,items:[
                        Employee_ShowEmployeeForm_MobileNo
                    ]},
                    {columnWidth:.5,layout:'form',border:false,items:[
                        Employee_ShowEmployeeForm_PhoneCall
                    ]}                        
              ]},
              {layout:'column',border:false,items:[
                    {columnWidth:.5,layout:'form',border:false,items:[
                        Employee_ShowEmployeeForm_Birthday
                    ]},
                    {columnWidth:.5,layout:'form',border:false,items:[
                        Employee_ShowEmployeeForm_Department
                    ]}                        
              ]},
              {layout:'column',border:false,items:[
                    {columnWidth:.5,layout:'form',border:false,items:[
                        Employee_ShowEmployeeForm_Sex
                    ]},
                    {columnWidth:.5,layout:'form',border:false,items:[
                        Employee_ShowEmployeeForm_Duty
                    ]}                        
              ]}
        ] 
    });
},
//************************************提交按钮事件<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
AppendButtonDell:function(){
    if (this.fp.form.isValid()){
        this.fp.form.doAction('submit',
        {
            url : 'JSON/System/Employee.aspx',
            mothed:'POST',
            waitMsg:'正在提交。。。',
            params : {FunctionName : 'Sys_Employee_AddEmployee'},
            success : function(form, action){
                var json = action.result.success;
                if (json){
                   Ext.Msg.alert('系统提示','新职员数据成功!');
                   this.fp.form.reset();
                   if (this.EmployeeEditWindow_RefreshStore){
                        this.EmployeeEditWindow_RefreshStore.reload();
                   }
                }
                else{
                   Ext.Msg.alert('系统提示','数据提交失败,请重试!');
                }                                                
            }.createDelegate(this),
            failure : function(form, action){
                switch (action.failureType){                
                    case Ext.form.Action.CLIENT_INVALID:
                        Ext.Msg.alert("错误", "提交的表单数据无效,请检查!");
                        break;
                    case Ext.form.Action.CONNECT_FAILURE:
                        Ext.Msg.alert("错误", "服务器连接失败,请稍后再试!");
                        break;
                    case Ext.form.Action.SERVER_INVALID:
                      Ext.Msg.alert("错误", "提交服务器出错,请联系管理员!");
                }
            }.createDelegate(this)
        });            
    }
    else {
        Ext.Msg.alert('系统提示','有必填项没有填写或者两次密码不一致,请检查!');
    };
},
//************************************初始化页面事件<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
InitData:function(){
    if (this.EmployeeEditWindow_WindowType == 'add'){
        return;
    };
    if (this.EmployeeEditWindow_InitData[0]){
        if (this.fp){
            this.fp.form.loadRecord(this.EmployeeEditWindow_InitData[0]);
        }
    }
    this.EmployeeEditWindow_ID = this.EmployeeEditWindow_InitData[0].get('ID');
},
//************************************取消按钮事件<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
CancelButtonDell:function(){
    if (this){
        this.close();
    }        
},
//************************************初始化界面<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
initComponent : function(){
    Ext.ux.EmployeeEditWindow.superclass.initComponent.call(this);
    this.fp = this.initFormPanel();
    this.add(this.fp);
    this.addButton('取  消',this.CancelButtonDell,this);
    this.addButton('提  交',this.AppendButtonDell,this);
    if (this.EmployeeEditWindow_WindowType == 'add'){
        this.title = '添加员工'
    }
    else if (this.EmployeeEditWindow_WindowType == 'edit'){
        this.title = '修改员工'
    };
}
//************************************初始化界面<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

})
[/code]
[b]问题补充:[/b]
我修改成这个样子
[code="java"]
Ext.ux.EmployeeEditWindow = function(config){
//窗体隐藏属性 员工ID 新增为0
this.EmployeeEditWindow_ID = '-1';
//提交按钮的事件
this.EmployeeEidtWindow_SubmitFun = config.EmployeeEidtWindow_FunSubmit;
//窗口类型 'Add','Edit'
this.EmployeeEditWindow_WindowType = config.EmployeeEditWindow_WindosType;
//初始化数据
this.EmployeeEditWindow_InitData = config.EmployeeEditWindow_InitData;
//提交完毕后 需要刷新的storedata
this.EmployeeEditWindow_RefreshStore = config.EmployeeEditWindow_RefreshStore;

var sss = 'dddd';

Ext.ux.EmployeeEditWindow.superclass.constructor.call(this,config);

}
[/code]

但是在下面
Ext.extend(Ext.ux.EmployeeEditWindow,Ext.Window,{
。。。。
}
好像无法访问到sss 应该如何访问sss呢?

另外 我页面中有几个combobox 但是我发现点击修改后 字典没有翻译成为数据 为什么?应该怎么处理呢?谢谢

  • 写回答

2条回答 默认 最新

  • chanball 2009-12-16 15:51
    关注

    sss 只在构造方法内有效,如果想在Ext.extend(Ext.ux.EmployeeEditWindow,Ext.Window,{
    。。。。
    }
    里的方法调用sss,那么只有用
    this.sss进行声明,然后在Ext.extend(Ext.ux.EmployeeEditWindow,Ext.Window,{
    。。。。
    }
    里的方法内用this.sss进行调用,

    又或者你把方法写在构造方法内也行,不过比较难看

    [quote]另外 我页面中有几个combobox 但是我发现点击修改后 字典没有翻译成为数据 为什么?应该怎么处理呢?谢谢[/quote]

    你可以在load表单数据的回调函数success里对combo进行赋值,如下
    [code="js"]
    //注意下面顺序
    combo.setValue(value);//设置隐藏值
    combo.setRawValue(text);//设置显示值
    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘