在 ExtJS 4 中填充存储中的窗体



我使用以下代码将数据从我的存储加载到 ExtJs 中的表单,但我无法将数据检索到我的文本字段。

Ext.onReady(function() {
var formPanel = Ext.create('Ext.form.Panel', {
       title: 'Form Panel',
       width: 350,
       height: 200,
       style: 'margin: 50px',
       renderTo: 'musicianProfile', // the name of the div in my JSP
       reader: new Ext.data.JsonReader({
           type: 'json',
           root: 'data',             
           fields: [
                    {name: 'firstName', type: 'string'},
                    {name: 'lastName', type: 'string'}
                ]
       }),     
       items: [{
        xtype: 'container',
            layout: 'hbox',
            items: [{
                 fieldLabel: 'First Name',
                 xtype: 'textfield',
                 name: 'firstName',
                 readOnly: true,
                 flex: 1,
            }, {
                 fieldLabel: 'Last Name',
                 xtype: 'textfield',
                 name: 'lastName',
                 readOnly: true,
                 flex: 1,
             }]
     }]
    });
    formPanel.getForm().load({
        method:'GET',
        url:'ajax/viewMusicianMembers.htm' //URL that produces a JSON result
    });
});

我收到的浏览器值是:

{
     "success":true,"total":1,"message":null,
     "data":[{"firstName":"System","lastName":"Administrator"}],
     "errors":null
}

谁能帮我找出错误在哪里,以及如何纠正它?

试试这个,

formPanel.getForm().load({
    method:'GET',
    url:'ajax/viewMusicianMembers.htm', //URL that produces a JSON result
    success: function(response, options) {
      formPanel.getForm().setValues(Ext.JSON.decode(response.data));
    },
    failure: function (response, options) {
    }
});

最新更新