ExtJS弹出窗口表单数据加载

问题描述 投票:0回答:2

我使用网格面板。当我在网格中选择行时,我得到以下结果:

  • 如果我在'document.body'中渲染表单,一切正常,填写表单字段。
  • 如果我,同一窗体在窗口面板中启动,表单字段为空。
  • 当我同时使用它们时,将关闭在'document.body'中呈现的Form,并填充Window中的Form字段。

我犯错的地方。

// Grip panel part
sm: new Ext.grid.RowSelectionModel({
        singleSelect: true,
        listeners: {
                    rowselect: function(sm, index, record) {deleteWindow.show();}
                   }
        })  
// End Grid panel part      

var myForm = new Ext.form.FormPanel({
        title:"Basic Form",
        width:425,
        frame:true,
        items: [
            new Ext.form.TextField({
                id:"to",
                fieldLabel:"To",
                width:275,
                allowBlank:false,
                blankText:"Please enter a to address",
                     readOnly: true
            }),
            new Ext.form.TextField({
                id:"subject",
                fieldLabel:"Subject",
                width:275,
                allowBlank:false,
                blankText:"Please enter a subject address",
                readOnly: true
            }),
        ],
        buttons: [
            {text:"Cancel"},
            {text:"Save"}
        ]
    });

var deleteWindow = new Ext.Window({
        id: 'id_deleteWindow',
        title: 'Delete',
        closable:true,
        width: 750,
        height:     380,
        plain:true,
        layout: 'fit',
        items: myForm
});

var id_test = 2;  // This is only for this problem

//myForm.render(document.body);  // When using this code everything is ok, and form fields are filled


myForm.getForm().load({
                url:'ggg.php',
                params:{
                        id: id_test
                         }
});

JSON数据

{success:true,results:[{"id_test":"1","to":"a","subject":"aa"}]}
extjs extjs3
2个回答
0
投票

我建议对代码进行以下更改:

  1. 代替在TextField上使用id属性(例如,id:'subject'),使用name属性(name:'subject')
  2. 好奇....因为你正在处理网格上的rowselect事件,你可能想要在表单面板中加载选定的记录而不是再次加载它。如果是这种情况,那么您可以在窗体面板上调用loadRecord()方法并将记录对象传递给它,然后在窗口上调用show()方法

0
投票

我发现当在形式上调用load时,ExtJS尝试访问form dom元素以确定形式method。我找到了2个解决方案:

  1. method添加到表单配置中
  2. 显示窗口后加载数据

这是第二个解决方案的代码:

var deleteWindow = new Ext.Window({
    id: 'id_deleteWindow',
    title: 'Delete',
    closable:true,
    width: 750,
    height:     380,
    plain:true,
    layout: 'fit',
    items: myForm,
    listeners: {
        show: function() {
            var form = this.items.get(0);
            form.getForm().load({
                url:'ggg.php',
                params:{
                    id: id_test
                }
            });
        }
    }
});
deleteWindow.show();
© www.soinside.com 2019 - 2024. All rights reserved.