Загрузить форму из комбо - PullRequest
       6

Загрузить форму из комбо

1 голос
/ 30 августа 2011

Я пытаюсь загрузить форму из записи, выбранной в комбо.

Хранилище загружено правильно, и поле со списком заполнено, но, когда я выбираю значение из поля со списком, поля формы остаются пустыми.

Любая помощь будет оценена.

Это код:

Модель:

Ext.define('AA.model.proc.Process', {
    extend: 'Ext.data.Model',
    fields: [
     { name: 'name', type: 'string' },
     { name: 'owner', type: 'string' },
     { name: 'mail_dest', type: 'string' }
    ],
    proxy: {
     type: 'rest',
     url : 'data/camp.json',
     reader: {
        type: 'json',
        root: 'camp',
        totalProperty: 'count'
    }
}
});

Магазин:

Ext.define('AA.store.proc.Process', {
    extend: 'Ext.data.Store',
    model: 'AA.model.proc.Process',
    requires: 'AA.model.proc.Process'
});

Класс:

Ext.define('AA.view.proc.IM', {
    extend: 'Ext.window.Window',
    alias: 'widget.im',
    title: 'IM',
    layout: 'fit',
    height: 500,
    width: 400,
    autoShow: true,
    plain: true,
    modal: true,
    headerPosition: 'right',
    closable: false,
    initComponent: function () {
        this.items = [{
            xtype: 'form',
            fileUpload: true,
            width: 550,
            autoHeight: true,
            border: false,
            bodyStyle: 'padding:5px 5px 0',
            frame: true,
            labelWidth: 100,
            defaults: {
                anchor: '95%',
                allowBlank: false,
                msgTarget: 'side'
            },
            items: [{
                xtype: 'combo',
                name: 'name',
                store: 'procstore',
                fieldLabel: 'Name',
                valueField: 'name',
                displayField: 'name',
                width: 150,
                allowBlank: true,
                listeners: {
                    scope: this,
                        'select': this.loadForm
                }
            }, {
                xtype: 'textfield',
                fieldLabel: 'Name',
                name: 'name'
            }, {
                xtype: 'textfield',
                fieldLabel: 'Owner',
                name: 'owner'
            }, {
                xtype: 'textfield',
                fieldLabel: 'E-mail owner',
                name: 'mail_dest'
            }]
        }];
        this.buttons = [{
            text: 'Save',
            action: 'save'
        }, {
            text: 'Cancel',
            scope: this,
            handler: this.close
        }];
        this.callParent(arguments);
    },
    loadForm: function (field, record, option) {
        console.log(record)
        // firebug returns 
        //  $className "AA.model.proc.Process"
        //  $alternateClassName     "Ext.data.Record"
        console.log(this.down('form'))
        // firebug returns the right form panel
        this.down('form').loadRecord(record);
    }
});

1 Ответ

0 голосов
/ 31 августа 2011

Это из документации для события select:

select (комбинированный Ext.form.field.ComboBox, Записи массива Object eOpts)

Обратите внимание, что вторым параметром является массив.Но в вашем примере вторым параметром является Ext.data.Record.Вы рассматриваете массив как запись.Измените ваш loadForm, чтобы он обрабатывал массивы записей:

loadForm: function (field,records,option) {
    this.down('form').loadRecord(records[0]);
}

PS Кстати, у вас есть два поля с name: 'name'.

...