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
Forms 自动填充组合框ExtJS_Forms_Extjs_Combobox - Fatal编程技术网

Forms 自动填充组合框ExtJS

Forms 自动填充组合框ExtJS,forms,extjs,combobox,Forms,Extjs,Combobox,我有一些组合框,它们在表单中具有预定义的值。但是,当用户提交表单并且我使用以下方法重置时,它工作正常: this.getView().getForm().reset() 这将在大多数区域完全重置表单,并且组合框将再次填充预定义值,但是,如果您将值保留在新表单中并再次提交,则将收到一个“无法读取null属性“0”的错误” 我如何预填充值: xtype: 'combobox', fieldLabel: '<span style="color: red;

我有一些组合框,它们在表单中具有预定义的值。但是,当用户提交表单并且我使用以下方法重置时,它工作正常:

    this.getView().getForm().reset()
这将在大多数区域完全重置表单,并且组合框将再次填充预定义值,但是,如果您将值保留在新表单中并再次提交,则将收到一个“无法读取null属性“0”的错误”

我如何预填充值:

       xtype: 'combobox',
        fieldLabel: '<span style="color: red; font-weight: bold;">*</span> <span style="font-weight: bold;">Are there any injuries or Fatalities?<span>',
        id: 'injuriesFatalities',
        labelWidth: 400,
        labelAlign: 'right',
        allowBlank: false,
        displayField: 'name',
        value: 'No',
        store: Ext.create('Ext.data.Store', {
            fields: ['name'],
            data: [{ name: 'No' }, { name: 'Yes' }]
        })
xtype:'combobox',
fieldLabel:“*是否有人受伤或死亡?”,
id:“伤亡人数”,
标签宽度:400,
labelAlign:'对',
allowBlank:false,
displayField:'名称',
值:'否',
存储:Ext.create('Ext.data.store'{
字段:['name'],
数据:[{name:'No'},{name:'Yes'}]
})
为避免此错误,用户当前需要做的是在组合框中重新选择当前选择的内容。如果我回答了以下问题之一,我觉得我可以避免这个问题:

A) 如何正确设置预定义的组合框值,或

B) 如何正确清除表单而不出现此错误

简介

目标:

  • 需要清除表单(表单当前已清除)
  • 需要预填充组合框的值(表单当前填充可见的组合框)
  • 问题:

    -即使在表单重置后combobox选择了值,combobox也不会实际保存正确的值

    引发错误:


    无法读取null的属性“0”

    组合框配置中缺少值字段。此外,还需要在数据中指定指定的valuefield。 您始终可以重用相同的字段,但最好将displayField和valueField保留为不同的键,以便轻松识别它们

    下面是一个如何执行此操作的示例:

    Ext.application({
        name: 'Fiddle',
    
        launch: function () {
    
            var store = Ext.create("Ext.data.Store", {
                fields: ['name', 'age'],
                data: [{
                    name: 'Test1',
                    age: 22,
                    value: 'test1'
                }, {
                    name: 'Test2',
                    age: 23,
                    value: 'test2',
                }, {
                    name: 'Test3',
                    age: 24,
                    value: 'test3'
                }]
            });
    
            Ext.Viewport.add({
                xtype: 'panel',
                layout: 'fit',
                title: 'Form Exmaple',
                items: [{
                    xtype: 'formpanel',
                    id: 'formId',
                    items: [{
                        xtype: 'combobox',
                        store: store,
                        displayField: 'name',
                        valueField: 'value',
                        value: 'test2'
                    }],
                    buttons: [{
                        text: 'Reset',
                        handler: function(me) {
                            var form = Ext.getCmp('formId');
                            form.reset();
                        }
                    }]
                }]
            });
        }
    });
    

    提琴示例:

    组合框配置中缺少值字段配置。此外,还需要在数据中指定指定的valuefield。 您始终可以重用相同的字段,但最好将displayField和valueField保留为不同的键,以便轻松识别它们

    下面是一个如何执行此操作的示例:

    Ext.application({
        name: 'Fiddle',
    
        launch: function () {
    
            var store = Ext.create("Ext.data.Store", {
                fields: ['name', 'age'],
                data: [{
                    name: 'Test1',
                    age: 22,
                    value: 'test1'
                }, {
                    name: 'Test2',
                    age: 23,
                    value: 'test2',
                }, {
                    name: 'Test3',
                    age: 24,
                    value: 'test3'
                }]
            });
    
            Ext.Viewport.add({
                xtype: 'panel',
                layout: 'fit',
                title: 'Form Exmaple',
                items: [{
                    xtype: 'formpanel',
                    id: 'formId',
                    items: [{
                        xtype: 'combobox',
                        store: store,
                        displayField: 'name',
                        valueField: 'value',
                        value: 'test2'
                    }],
                    buttons: [{
                        text: 'Reset',
                        handler: function(me) {
                            var form = Ext.getCmp('formId');
                            form.reset();
                        }
                    }]
                }]
            });
        }
    });
    

    提琴示例:

    感谢您的帮助,这是关于如何选择id的另一个问题。我使用的是:损害赔偿。lastSelectedRecords[0]。id;我需要进行损坏。valueCollection.items[0]。id感谢您的帮助,这是关于如何选择id的另一个问题。我使用的是:损坏。lastSelectedRecords[0]。id;我需要进行损坏。valueCollection.items[0]。id