1

私はフォームにコンボボックスを持っています:

{
    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

ここで、ユーザーを編集するときに何も触れないと、コンボボックスのサーバーで「管理者」(displayField) が取得されますが、コンボボックスで何かを変更すると「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
        },
});

悲しいことに、コンボボックスを押したときに既に読み込まれているため、ストアはすべてのデータを取得しています。これは、'id' および 'name' プロパティを持つ単純な JSON です。

EDIT2:コンボボックスで選択された正しいデータを取得していなかったため、管轄区域でこれを試しました。これは私のコントローラーの中にあります。

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);
    }
4

2 に答える 2

1

それは意味がありません...コンボを正しい方法で読み上げる場合、つまり、フォームに作業をさせるか、自分で getSubmitValue() を呼び出すと、コンボは常にvalueField. hiddenName他の目的に使用されます。このJSFiddleのコンソールを見て、コンボ値を取得する方法を再確認してください。

これが実際のデモコードです

// 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()); })
于 2013-03-28T07:33:02.667 に答える
0

助けてくれたすべての人に+1しますが、問題はここにありました:

私の店では autoLoad: false を置き、コンボボックスの中に store.load() を手動で入れましたが、完全に機能します。

皆さん、ありがとうございました!:)

于 2013-03-28T10:09:23.000 に答える