Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Extjs-使用存储区填充组合框不匹配_Extjs - Fatal编程技术网

Extjs-使用存储区填充组合框不匹配

Extjs-使用存储区填充组合框不匹配,extjs,Extjs,我需要填充一个带有商店的组合框,除了一件事,所有的工作都很好。?为什么商店只填充显示字段,而不填充值字段 在这一行 form.loadRecord(records[1]); 我在表单中设置了该记录,这很好,但当我尝试提交表单时,我希望值为“2”,而不是“Media” 为了更好地解释,我们在JSFIDLE上提供了代码和示例 谢谢。当您调用form.getValues()时,您只会得到值,如果您想要关联记录中的值,您必须搜索存储 关键在于理解getValues()只需为表单中的每个字段调用ge

我需要填充一个带有商店的组合框,除了一件事,所有的工作都很好。?为什么商店只填充显示字段,而不填充值字段

在这一行

form.loadRecord(records[1]); 
我在表单中设置了该记录,这很好,但当我尝试提交表单时,我希望值为“2”,而不是“Media”

为了更好地解释,我们在JSFIDLE上提供了代码和示例


谢谢。

当您调用
form.getValues()
时,您只会得到值,如果您想要关联记录中的值,您必须搜索存储


关键在于理解
getValues()
只需为表单中的每个字段调用
getValue()
getValue
不返回记录,只返回您告诉它要使用的记录中的字段
valueField:'id',

这是因为form.loadRecord()并没有完全按照您的期望执行。 您希望它做的是告诉combobox使用该特定记录(记录[1])。 它实际上是告诉combobox:“现在将您的值设置为媒体”,combobox礼貌地这样做,尽管它太“愚蠢”了,无法将它与特定的记录相关联

以下是固定版本,不确定此类解决方案是否适合您的需要:


我想您误解了
ComboBox.select()
Form.loadRecord()
Form.getValues()
的功能。您的示例仍然只显示id。有关解释,请参阅我的答案。
    var store = Ext.create('Ext.data.Store', {
        fields: ['id', 'status'],

        data: [
                { id: '1', status: 'Baja' },
                { id: '2', status: 'Media' },
                { id: '3', status: 'Alta' },
                { id: '4', status: 'Urgente' }
        ]
    });

    var formPanel = Ext.create('Ext.form.Panel', {
        title: 'Edit Country',
        url: 'http://aaa.com/',
        items: [
            {
                xtype: 'combobox',
                fieldLabel: 'Nombre',
                name: 'status',
                anchor: '50%',                          
                displayField: 'status',            
                valueField: 'id',
                store: store
            }
        ],
        buttons: [
            {
                text: 'Guardar',
                handler: function () {
                    var form = formPanel.getForm();
                    var value = form.getValues();

                    alert(value.status);
                }
            }
        ],
        renderTo: Ext.getBody()
    });



    store.load({
        scope: this,
        callback: function(records, operation, success) {
            var form = formPanel.getForm();
            form.loadRecord(records[1]);
        }
    });
    var rec = store.getById(value.status);                
    alert(rec.get('status'));
var store = Ext.create('Ext.data.Store', {
    fields: ['id', 'status'],

    data: [
            { id: '1', status: 'Baja' },
            { id: '2', status: 'Media' },
            { id: '3', status: 'Alta' },
            { id: '4', status: 'Urgente' }
    ]
});

var formPanel = Ext.create('Ext.form.Panel', {
    title: 'Edit Country',
    url: 'http://aaa.com/',
    items: [
    {
        xtype: 'combobox',
        fieldLabel: 'Nombre',
        name: 'status',
        anchor: '50%',                          
        displayField: 'status',            
        valueField: 'id',
        store: store
    }
    ],
    buttons: [
    {
        text: 'Guardar',
        handler: function () {
        var form = formPanel.getForm();
        var value = form.getValues();
        alert(value.status);
        }
    }
    ],
    renderTo: Ext.getBody()
});



store.load({
    scope: this,
    callback: function(records, operation, success) {
    // the operation object
    // contains all of the details of the load operation
    //var form = formPanel.getForm();
    //form.loadRecord(records[1]);
    formPanel.items.first().select(records[1]);
    }
});