简体   繁体   English

在ExtJS中,getForm()。load()是否加载组合字段值?

[英]In ExtJS does getForm().load() load combo field values?

I have a form with a combo box in it. 我有一个带有组合框的表格。 The combo box loads it's data via a Json store and I use form.getForm().load( url: 'URL') to load the forms data also from a Json store. 组合框通过Json商店加载其数据,我使用form.getForm()。load(url:'URL')从Json商店也加载表单数据。

When the data is loaded into the form I can see via Firebug that it receives the right value, the combo then displays the correct corresponding display value. 当数据加载到窗体中时,我可以通过Firebug看到它收到正确的值,然后该组合显示正确的对应显示值。 When I look at the HTML in FireBug for the hiddenField it says the value="DISPLAYVALUE" not value="VALUE". 当我查看FireBug中的HTML中的hiddenField时,它说的是value =“ DISPLAYVALUE”而不是value =“ VALUE”。 When I then pick any value from the combo it changes to the correct value="VALUE". 然后,当我从组合中选择任何值时,它将更改为正确的值=“ VALUE”。

Of course if the user never changes the combo the wrong value is submitted. 当然,如果用户从不更改组合,则会提交错误的值。 Is this by design/limitation or am I missing something. 这是设计/限制还是我缺少什么?

Do I really need to load and verify the data for each combo before I do the getForm().load()? 在执行getForm()。load()之前,是否真的需要加载并验证每个组合的数据? wouldn't it make sense for load() to just load the complete data even if that means loading the data from a store? load()仅加载完整数据是否有意义,即使这意味着要从商店加载数据?

I've included simplified sample code that has the issue. 我已经包含了有问题的简化示例代码。

    Ext.onReady(function(){

    var frmClientRecord = {
        xtype: 'form',
        items: [
            {
                fieldLabel: 'Advisor',
                xtype: 'combo',
                id: 'advisorName',
                displayField: 'Advisor',
                valueField: 'advisorId',
                hiddenName: 'advisorsId',
                mode: 'remote',
                store: new Ext.data.Store({
                    autoLoad: true,
                    proxy: new Ext.data.HttpProxy({
                        url: '/referrals/index.php/advisors/read',
                        method: 'POST'
                        }),
                    reader: new Ext.data.JsonReader({
                        root: 'results',
                        fields: [
                            {name: 'advisorId'},
                            {name: 'Advisor'}
                        ]
                    })
                })
            }
        ]
    }

    frmClientRecordCmp = new Ext.FormPanel(Ext.apply(frmClientRecord));


    frmClientRecordCmp.getForm().load({
        url: '/referrals/index.php/clients/getbyid/100',
    })

    frmClientRecordCmp.render(document.body);
});

JSON FOR THE COMBO 组合的JSON

({"results":[{"Advisor":"Chris","advisorId":33},{"Advisor":"Fawzia","advisorId":2},{"Advisor":"Kent","advisorId":3},{"Advisor":"Rob","advisorId":4},{"Advisor":"Stephanie","advisorId":5}]})

JSON FOR THE FORM 表单的JSON

{success: true, data: {"advisorsId":33}}

This could happen if your form is loading before the combo store loads. 如果在组合存储加载之前加载表单,则可能会发生这种情况。 (Given that rest of your code looks Ok) (鉴于您的其余代码看起来还可以)

I suspect this will resolve if you render your form before loading it. 我怀疑如果您在加载表单之前就渲染了表单,这将会解决。
(move frmClientRecordCmp.render(document.body); one statement up in your sample code) (将frmClientRecordCmp.render(document.body);移动frmClientRecordCmp.render(document.body);在示例代码中向上移动一条语句)

EDIT 编辑
Two points to consider- 有两点要考虑-

  1. Are you sure the combo store has finished loading before the form loads? 确定组合商店在表单加载之前已经完成加载吗?
  2. Looking at ComboBox's valueField documentation, it looks like a call to combo.setValue may be necessary after the form loads. 查看ComboBox的valueField文档,看起来在表单加载后可能需要调用combo.setValue。 Something along the lines of - 类似于-

    frmClientRecordCmp.getForm().load({ url: '/referrals/index.php/clients/getbyid/100', success:function(form,action){ form.findField('advisorName').setValue(action.result.data.advisorId); } }); frmClientRecordCmp.getForm()。load({url:'/referrals/index.php/clients/getbyid/100',success:function(form,action){form.findField('advisorName')。setValue(action.result。 data.advisorId);}});

It was a problem I had caused by using the id: 'advisorName'. 这是我使用ID:“ advisorName”引起的问题。 I was returning a field also named 'advisorName' so it was filling it even though I was specifying a hiddenName value. 我返回的字段也称为“ advisorName”,因此即使我指定了hiddenName值,它也会填充它。 The moral is make sure your id is unique and not a field name. 道德是确保您的ID是唯一的,而不是字段名。

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

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