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 Ext JS 4-向服务器提交combobox时的奇怪行为_Extjs_Extjs4 - Fatal编程技术网

Extjs Ext JS 4-向服务器提交combobox时的奇怪行为

Extjs Ext JS 4-向服务器提交combobox时的奇怪行为,extjs,extjs4,Extjs,Extjs4,我有一个组合框,格式如下: { xtype: 'combobox', fieldLabel: 'Jurisdictions', name: 'jurisdiction_id', id: 'ComboboxJurisdictions', store: Ext.create('App.store.Jurisdictions'), queryMode: 'local', editable: false, displayField: 'na

我有一个组合框,格式如下:

{
    xtype: 'combobox',
    fieldLabel: 'Jurisdictions',
    name: 'jurisdiction_id',
    id: 'ComboboxJurisdictions',
    store: Ext.create('App.store.Jurisdictions'),
    queryMode: 'local',
    editable: false,
    displayField: 'name',
    valueField: 'id',
}
数据如下:

1 => Administrator
2 => User
3 => Guest
现在,如果我在编辑用户时不碰任何东西,在我的combobox服务器上,我会得到“管理员”(displayField),但当我在combobox中更改某些内容时,我会得到“id”(valueField)。在这两种情况下我都只想要“id”。我在读关于
hiddenName
?是这样吗

如果您需要更多代码,请随时询问。:)

谢谢大家!

编辑(更多代码)

1.)没有默认值

以下是整个视图代码:

Ext.define('App.view.Suits.Update', {
    extend: 'Ext.window.Window',
    title: 'Suits',
    width: 250,
    id: 'UpdateWindowSuits',
    defaultType: 'textfield',
    items: [{
        xtype: 'UpdateFormSuits'
    }],
    buttons: [
      { text: 'Save', id: 'submitUpdateFormButtonSuits'},
      { text: 'Cancel', id: 'cancelUpdateFormButtonSuits'},
    ]
});

Ext.define('App.view.Suits.UpdateForm', {
    extend: 'Ext.form.Panel',
    alias: 'widget.UpdateFormSuits',
    layout: 'form',
    id: 'UpdateFormSuits',
    bodyPadding: 5,
    defaultType: 'textfield',
    items: [{
        fieldLabel: 'Id',
        name: 'id',
        hidden: true
    },{
        fieldLabel: 'Name',
        name: 'name',
        allowBlank: false,
    },{
        fieldLabel: 'Status',
        name: 'status',
        allowBlank: false

    },{
        xtype: 'combobox',
        fieldLabel: 'Priority',
        name: 'suit_priority_id',
        id: 'ComboboxSuitPriorities',
        store: Ext.create('App.store.SuitPriorities'),
        editable: false,
        displayField: 'name',
        hiddenName: 'id',
        valueField: 'id'
    },{
        xtype: 'combobox',
        fieldLabel: 'Jurisdictions',
        name: 'jurisdiction_id',
        id: 'ComboboxJurisdictions',
        store: Ext.create('App.store.Jurisdictions'),
        queryMode: 'local',
        editable: false,
        displayField: 'name',
        valueField: 'id',
    }],
});
这是商店:

Ext.define('App.store.SuitPriorities', {
    extend: 'Ext.data.Store',

    // Where is the Model.
    model: 'App.model.SuitPriority',

    // "id" of the Store.
    storeId: 'SuitPriorities',

    // Autoload all data on creation.
    autoLoad: true,

    // Number of records in one page (for pagination).
    pagesize: 20,

    // Proxy for CRUD.
    proxy: {

        // Type of request.
        type: 'ajax',

        // API for CRUD.
        api: {
            create  : 'php/suitpriorities/update',
            read    : 'php/suitpriorities/read',
            update  : 'php/suitpriorities/update',
            destroy : 'php/suitpriorities/delete'
        },

        // Type of methods.
        actionMethods: {
            create  : 'POST',
            read    : 'POST',
            update  : 'POST',
            destroy : 'POST'
        },

        // Reader.
        reader: {

            // Which type will the reader read.
            type: 'json',

            // Root of the data.
            root: 'suitpriorities',
            rootProperty: 'data',

            // One record.
            record: 'SuitPriority',

            // Message and success property.
            successProperty: 'success',
            messageProperty: 'message'
        },

        // Writer (when sending data).
        writer: {
            type: 'json',
            writeAllFields: true,
            root: 'data',
            encode: true
        },
});
正如我所悲伤的,商店正在获取所有数据,因为当我按下组合框时,它已经被加载了。它是一个简单的JSON,具有“id”和“name”属性

EDIT2:我在我的辖区尝试过这个方法,因为我没有在combobox中选择正确的数据。这是在我的控制器里面

onJurisdictionComboRender: function(combobox, eOpts){

        // Getting the selected row.
        var record = this.grid.getSelectionModel().getSelection()[0];

        // Selected jurisdiction.
        var jurisdiction = record.data.jurisdiction_id;

        // Select it in combobox.
        combobox.select(jurisdiction);
    }

那没有道理。。。如果您以正确的方式读取组合,意味着让表单自己执行工作或调用getSubmitValue(),组合将始终返回
值字段
<代码>隐藏名称用于其他目的。请查看此的控制台,并重新检查如何获取组合值

这是正在运行的演示代码

// The data store containing the list of states
var roles = Ext.create('Ext.data.Store', {
    fields: ['id', 'name'],
    data : [
        {"id":1, "name":"Administrator"},
        {"id":2, "name":"User"},
        {"id":3, "name":"Guest"}
        //...
    ]
});

// Create the combo box, attached to the states data store
var combo = Ext.create('Ext.form.ComboBox', {
    fieldLabel: 'Choose Role',
    store: roles,
    queryMode: 'local',
    editable: false,
    displayField: 'name',
    valueField: 'id',
    renderTo: Ext.getBody()
});

combo.on('select', function(cb){ console.log(cb.getSubmitValue()); })

那没有道理。。。如果您以正确的方式读取组合,意味着让表单自己执行工作或调用getSubmitValue(),组合将始终返回
值字段
<代码>隐藏名称用于其他目的。请查看此的控制台,并重新检查如何获取组合值

这是正在运行的演示代码

// The data store containing the list of states
var roles = Ext.create('Ext.data.Store', {
    fields: ['id', 'name'],
    data : [
        {"id":1, "name":"Administrator"},
        {"id":2, "name":"User"},
        {"id":3, "name":"Guest"}
        //...
    ]
});

// Create the combo box, attached to the states data store
var combo = Ext.create('Ext.form.ComboBox', {
    fieldLabel: 'Choose Role',
    store: roles,
    queryMode: 'local',
    editable: false,
    displayField: 'name',
    valueField: 'id',
    renderTo: Ext.getBody()
});

combo.on('select', function(cb){ console.log(cb.getSubmitValue()); })

+感谢大家的帮助,但问题就在这里:

在我的应用商店中,我将autoLoad:false放入组合框中,并手动将store.load()放入组合框中,它工作得非常好


谢谢大家!:)

+1感谢大家的帮助,但问题就在这里:

在我的应用商店中,我将autoLoad:false放入组合框中,并手动将store.load()放入组合框中,它工作得非常好


谢谢大家!:)

你能把代码显示在使用它的地方吗?组合是否有默认值?没问题,请稍等……您还可以显示App.store.com的定义吗?它是否具有您在问题中提到的硬编码数据?能否请您共享
App.store.judictionary
的代码及其型号?99%您会找到答案您能否显示代码的使用位置?组合是否有默认值?没问题,请稍等……您还可以显示App.store.com的定义吗?它是否具有您在问题中提到的硬编码数据?您能否共享
App.store.judictionary
的代码及其型号?99%您将找到答案