hzp321 2013-09-24 20:38
浏览 285
已采纳

ext 再次打开含 formpanel的 窗口出错误

代码如下:
但第一次打开更新窗口是没有错误[img]http://dl2.iteye.com/upload/attachment/0089/6237/3a6ed15c-e7e6-30a0-9fad-c75e9df7485d.png[/img],
第二次打开时form里的部分东西会显示两次,而且会丢失表单里的数据

[img]http://dl2.iteye.com/upload/attachment/0089/6239/b322266c-0ad6-3964-a5ba-27e71649a812.png[/img]


[code="java"]{
text:'更新设备',
tooltip:'更新设备',
iconCls:'update',

        ref: '../updateButton',
        disabled: true,

        handler: function(){
            var record = grid4.getSelectionModel().getSelected();

            var form = new Ext.form.FormPanel({
                baseCls: 'x-plain',
                labelWidth: 55,
                autoDestroy : true,
                layout: {
                    type: 'form',
                    align: 'stretch'  // Child items are stretched to full width
                },
                defaults: {
                    xtype: 'textfield'
                },
                items: [{
                    value:record.get("deviceid"),
                    plugins: [ Ext.ux.FieldLabeler ],
                    id: 'deviceInfo.deviceid',
                    hidden:true
                    //hideLable:true
                },{
                    value:record.get("devicealias"),
                    plugins: [ Ext.ux.FieldLabeler ],
                    fieldLabel: '设备名称',
                    id: 'deviceInfo.devicealias'
                }, 
                {
                    value:record.get("deviceip"),
                    plugins: [ Ext.ux.FieldLabeler ],
                    fieldLabel: '设备IP',
                    id: 'deviceInfo.deviceip'
                },{
                    value:record.get("devicemac"),
                    plugins: [ Ext.ux.FieldLabeler ],
                    fieldLabel: '设备MAC',
                    id: 'deviceInfo.devicemac'
                },
                ]
            });
            //初始化设备类型
            var typesStore = new Ext.data.JsonStore({
                 url:'./initDeviceTypes.action',
                 fields: ['index','type']
            });
            typesStore.load(); 

            var deviceTypesCombo=new Ext.form.ComboBox({ 
                xtype : 'combo',
                fieldLabel : '设备类型',
                store : typesStore,
                editable : false,
                allowBlank : false,
                mode : 'local',
                triggerAction : 'all',
                editable : false,
                hiddenName : 'deviceInfo.devicetypeid',//要想向后台传递valueField必须设置此项
                valueField : 'index',
                displayField : 'type'
            });

            form.add(deviceTypesCombo);


            var w = new Ext.Window({
                title: '更新设备',
                collapsible: true,
                maximizable: true,
                width: 500,
                height: 400,
                minWidth: 300,
                minHeight: 200,
                autoDestroy : true,
                layout: 'fit',
                plain: true,
                bodyStyle: 'padding:5px;',
                buttonAlign: 'center',
                items: form,
                buttons: [{
                    text: '提交',
                    handler : function(){    

                        form.getForm().submit({    
                            url:'./updateDevice.action',
                            method: 'post',
                            waitTitle : '请等待' ,    
                            waitMsg: '正在提交中',    
                            success:function(form,action){    
                                if(action.result.res==0){
                                    w.hide();
                                    location.href="./device/listDevices.jsp";
                                    Ext.Msg.alert('提示',"修改成功");
                                }else{
                                    Ext.Msg.alert('提示','修改失败!');  
                                    w.hide();
                                }
                            },    
                            failure:function(form,action){    
                                Ext.Msg.alert('提示','修改失败!');  
                                w.hide();
                            }   
                       });    
                 }    
                },{
                    text: '取消',
                    handler : function(){
                        w.hide();
                        form.close();
                    }
                }]
            });
            w.show();
      } 
    }[/code]
  • 写回答

1条回答 默认 最新

  • 肥肚皮 2013-09-24 22:39
    关注

    大致看了下你这个点击更新设备这个操作的时候
    都会重新生成
    record
    typesStore
    form
    w
    这些对象
    第一种方法:
    建议你每次关闭win对象的时候直接用销毁方式进行
    handler : function(){

    // w.hide();

    w.close();
    }

    第二种方发
    将win对象定义到按键执行函数的外面
    点击的时候判断win对象是否存在存在就直接显示不存在就建立
    handler: function(){

    //var record = grid4.getSelectionModel().getSelected();

    if(w){
    原来那段程序
    }else{
    w.show();
    ....后面接form的赋值语句。
    }

    .......
    }
    你可以试着改下

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?