简体   繁体   English

Ext.form.Panel load()与loadRecord()

[英]Ext.form.Panel load() vs. loadRecord()

I have strange problem with loading form panel with json request response. 我在加载带有json请求响应的表单面板时遇到了奇怪的问题。 In previous projects I used to load detail panel from grid store by using loadRecord(record) The store has associated model so record's embedded objects are mapped to model's properties and form renders those fields without any problem. 在以前的项目中,我曾经使用loadRecord(record)从网格存储中加载详细信息面板,该存储具有关联的模型,因此Record的嵌入对象被映射到模型的属性,并且表单呈现这些字段没有任何问题。 Once I had to load form directly with response from form.load() I can't see properties from record's embedded objects. 一旦不得不使用form.load()的响应直接加载表单,就无法从记录的嵌入式对象中看到属性。 For example from json 例如从json

{
   "message":null,
   "success":true,
   "data":{
      "code":"1",
      "name":"Canon Canada",
      "modifiedBy":null,
      "modifiedAt":null,
      "address":{
         "street":"6390 Dixie",
         "suite":null,
         "city":"Mississauga",
         "provinceCode":"ON",
         "postalCode":"L5T1P7"
      },
    ...
   }
}

I see rendered 'code' and 'name' properties, but not 'street' and 'city'. 我看到了呈现的“代码”和“名称”属性,但没有看到“街道”和“城市”属性。

Here is form.Panel code 这是表格。面板代码

Ext.define('App.view.billto.BillToDetailForm' ,{
    extend  : 'Ext.form.Panel'
    ,layout: 'form'
    ,alias  : 'widget.BillToDetailForm'
    ,autoHeight: true
    ,bodyPadding: 10
    ,fieldDefaults: MainAppViewConfig.fieldDefaults
    ,defaults: {xtype: 'fieldcontainer',layout:'hbox', anchor: '100%'}
    ,items   : [    {   defaults: {xtype: 'textfield', allowBlank: false},
                items: [{name: 'code', fieldLabel:'Bill To Code'}
                    ,{name: 'name',fieldLabel: 'Name'}]}
            ,{  defaults: {xtype: 'textfield', allowBlank: false},
                items: [{name: 'address.suite', fieldLabel:'Suite'}
                    ,{name: 'address.street', fieldLabel:'Street'}]}
            ...         
        ]

    ,loadContentForCode: function(code){
        //this.getForm().trackResetOnLoad = true;
        this.getForm().load({   method: 'GET',url: 'billtoDetail',
                                params:{'code':code},
                                waitMsg: 'Loading...',
                                /*success:function(form, action) {
                                    console.log('BillToDetailForm:loadContentForCode callback on success '+this);
                                    var responseObj = Ext.JSON.decode(action.response.responseText,true);
                                    var billToModel = Ext.create('MPS.model.BillToModel',responseObj.data);
                                    form.loadRecord(billToModel);
                                }*/
                    });
    }
});

As you can see I even did unsuccessful attempt to reload form in success handler. 如您所见,我什至没有尝试在成功处理程序中重新加载表单,但均未成功。

Also I have noticed that var billToModel = Ext.create('MPS.model.BillToModel',responseObj.data); 我也注意到var billToModel = Ext.create('MPS.model.BillToModel',responseObj.data); hasn't properly populated model's fields 'street' and 'city'. 没有正确填充模型的字段“街道”和“城市”。 That's also might be the cause of the problem. 这也可能是问题的原因。

Ext.define('MPS.model.BillToModel', {
    extend: 'Ext.data.Model'
    ,idProperty:'code'
    ,fields: [
         {name: 'code', type: 'string'},
         {name: 'name', type: 'string'},
         {name: 'street',mapping:'address.street', type: 'string'},
         {name: 'city', mapping:'address.city', type: 'string'},
        ...
    ]
});

Could you please point the real cause of the problem or advice any solution. 您能否指出问题的真正原因或提出任何解决方案的建议。 Thank you. 谢谢。

I just made fiddle for you. 我只是为你摆弄。 Take a look how it is working and try the same with your code: 看看它是如何工作的,并尝试使用您的代码进行相同的操作:

Sencha Fiddle - How associated data works Sencha Fiddle-关联数据如何工作

If this something that you are looking for just mark as answered. 如果您要查找的内容只是标记为已回答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM