现在的位置: 首页 > 综合 > 正文

Extjs 解决Window嵌套FormPanel第一次打开关闭后第二次打开出错的问题

2012年08月22日 ⁄ 综合 ⁄ 共 841字 ⁄ 字号 评论关闭

刚一开始使用的是建立个函数

function createTestWindows(){

    var testFormPanel=new Ext.FormPanel({
        //...
        //中间代码省略
        //...
    });

    testFormPanel.getForm().load({
        clientValidation: false,
        url: 'testurl.aspx',
        waitMsg: '读取数据中...',
        method: 'GET'
    });

    var testWin = new Ext.Window({
        //...
        //代码省略
        items: [testFormPanel],
        //...
        //代码省略
    }).show();
}
但是这种设计有局限性,无法单独在其他地方使用createTestWindows内部的testFormPanel,我的解决想法是把testFormPanel放到外面,代码如下:
 
var testFormPanel;
function createTestFromPanel(){
    testFormPanel=new Ext.FormPanel({
        //...
        //中间代码省略
        //...
    });

    testFormPanel.getForm().load({
        clientValidation: false,
        url: 'testurl',
        waitMsg: '读取数据中...',
        method: 'GET'
    });
}

function createTestWindows(){
    createTestFromPanel();//每次重新打开后再重新建立FormPanel
    var testWin = new Ext.Window({
        //...
        //代码省略
        items: [testFormPanel],
        //...
        //代码省略
    }).show();
}
 
然后就可以在其他想用testFormPanel的地方用下面代码使用:
 
createTestFormPanel(); //别忘了先引用带有这个函数的js文件
testFromPanel.render(document.body);
【上篇】
【下篇】

抱歉!评论已关闭.