【问题标题】:how to set combobox id from the store data received in extjs 4如何从 extjs 4 中收到的存储数据中设置组合框 ID
【发布时间】:2012-03-27 14:18:47
【问题描述】:

我的表单面板中有一个组合框。最初,我使用该表单将有关公司的新信息添加到我的数据库中。

现在我有一个包含公司信息的网格,当我根据 ID 查询单击它时,它会返回有关公司商店的完整信息。

有了这些所有数据我还得到了组合框国家、州、城市的 ID,但我无法根据收到的国家 ID、州 ID、城市 ID 设置组合框的值.

下面提到了我的 json 公司数据

    {
    "companydata": [{
        "city": {
            "cityname": "Patna",
            "stateid": 2,
            "cityid": 2,
            "cityzipcode": null
        },
        "cmpname": "Kintu Designs Pvt ltd",
        "cmptitle": "Kintu Designs Pvt ltd",
        "cmpcontact": "8128812153",
        "cmpdesc": "<b>?Kintu designs Surat</b>",
        "cmpfax": "8128812153",
        "cmpwebsite": "www.kintudesigns.com",
        "cmpemail1": "yaryan997@gmail.com",
        "cmpemail2": "yaryan997@gmail.com",
        "cmplogo": "calendar.png",
        "cmplogopath": "upload/images/",
        "cmpaddress": "Kintu designs Surat",
        "cmpcreatedby": 1,
        "cmpcreatedon": 1199932743000,
        "cmpmodifiedon": 1199932743000,
        "cmpmodifiedby": 0,
        "id": 1,
        "state": {
            "statename": "Bihar",
            "countryid": 1,
            "stateid": 2
        },
        "country": {
            "countryid": 1,
            "countryname": "India"
        }
    }],
    "total": 1,
    "success": true
}

现在基于它我想设置我的编辑表单的值。所有的值都设置得很完美,只有组合框的值设置不完美。

我的编辑窗口代码如下

Ext.define('rms.view.companymgt.companyEdit', {
    extend: 'Ext.window.Window',
    alias: 'widget.companyeditwindow',
    id: 'companyeditwindow',
    editform:1,
    itemId: 'companyeditwindow',
    store: 'companyStore',
    constrain: true,
    height: 595,
    width: 875,
    layout: {
        type: 'column'
    },
    title: 'Company',

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'form',
                    itemId: 'editmainform',
                    frame: true,
                    height: 546,
                    margin: 2,
                    width: 838,
                    layout: {
                        type: 'column'
                    },
                    bodyPadding: 10,
                    preventHeader: true,
                    title: 'My Form',
                    items: [
                    {

                        xtype: 'fieldset',
                        height: 134,
                        margin: 2,
                        width: 400,
                        title: 'Company Information',
                        items: [
                        {
                            xtype: 'textfield',
                            id: 'cmptitle',
                            itemId: 'cmptitle',
                            margin: 5,
                            width: 366,
                            name: 'cmptitle',
                            fieldLabel: 'Company Title',
                            anchor: '100%'
                        },
                        {
                            xtype: 'textfield',
                            id: 'cmpname',
                            itemId: 'cmpname',
                            margin: 5,
                            name: 'cmpname',
                            fieldLabel: 'Company Name',
                            anchor: '100%'
                        },
                        {
                            xtype: 'textfield',
                            id: 'cmpwebsite',
                            itemId: 'cmpwebsite',
                            margin: 5,
                            name: 'cmpwebsite',
                            fieldLabel: 'Website',
                            anchor: '100%'
                        }
                    ]
                },
                {
                    xtype: 'fieldset',
                    height: 138,
                    margin: 2,
                    width: 400,
                    title: 'Company Contact',
                    items: [
                        {
                            xtype: 'textfield',
                            id: 'cmpfax',
                            itemId: 'cmpfax',
                            margin: 5,
                            name: 'cmpfax',
                            fieldLabel: 'Fax No',
                            anchor: '100%'
                        },
                        {
                            xtype: 'textfield',
                            id: 'cmpcontact',
                            itemId: 'cmpcontact',
                            margin: 5,
                            name: 'cmpcontact',
                            fieldLabel: 'Contact No',
                            anchor: '100%'
                        },
                        {
                            xtype: 'textfield',
                            id: 'cmpemail1',
                            itemId: 'cmpemail1',
                            margin: 5,
                            name: 'cmpemail1',
                            fieldLabel: 'Email',
                            anchor: '100%'
                        },
                        {
                            xtype: 'textfield',
                            id: 'cmpemail2',
                            itemId: 'cmpemail2',
                            margin: 5,
                            name: 'cmpemail2',
                            fieldLabel: 'Other Email',
                            anchor: '100%'
                        }
                    ]
                },
                {
                    xtype: 'fieldset',
                    height: 350,
                    margin: 2,
                    width: 397,
                    title: 'Company Address',
                    items: [
                        {
                            id: 'btn-add-country',
                            itemId: 'btn-add-country',
                            xtype: 'button',
                            margin: '4 0 0 303',
                            style: 'position:absolute;',
                            width: 71,
                            text: 'Add Country',
                            action: 'btn-add-country'
                        },
                        {
                             xtype: 'combobox',
                            id: 'countryname',
                            itemId: 'countryname',
                            name: 'countryid',
                            margin: 5,
                            width: 294,
                            fieldLabel: 'Country',
                            emptyText: 'Select Country...',
                            displayField: 'countryid',
                            store: 'country',
                            valueField: 'countryid'
                        },
                        {
                            xtype: 'button',
                            id: 'btn-add-state',
                            itemId: 'btn-add-state',
                            margin: '0 0 0 303',
                            style: 'position:absolute;',
                            width: 71,
                            text: 'Add State',
                            action: 'btn-add-state'
                        },
                        {
                            xtype: 'combobox',
                            id: 'statename',
                            itemId: 'statename',
                            margin: 5,
                            width: 294,
                            name: 'stateid',
                            fieldLabel: 'State',
                            emptyText: 'Select State...',
                            displayField: 'stateid',
                            store: 'state',
                            valueField: 'stateid'
                        },
                        {
                            id: 'btn-add-city',
                            itemId: 'btn-add-city',
                            xtype: 'button',
                            margin: '0 0 0 303',
                            style: 'position:absolute;',
                            width: 71,
                            text: 'Add City',
                            action: 'btn-add-city'
                        },
                        {
                            xtype: 'combobox',
                            id: 'cityname',
                            itemId: 'cityname',
                            margin: 5,
                            width: 294,
                            name: 'cityid',
                            fieldLabel: 'City',
                            emptyText: 'Select City...',
                            displayField: 'cityid',
                            store: 'city',
                            valueField: 'cityid'
                        },
                        {
                            xtype: 'textareafield',
                            height: 75,
                            id: 'cmpaddress',
                            itemId: 'cmpaddress',
                            margin: 5,
                            width: 380,
                            name: 'cmpaddress',
                            fieldLabel: 'Address',
                            anchor: '100%'
                        },
                        {
                            xtype: 'htmleditor',
                            height: 146,
                            id: 'cmpdesc',
                            itemId: 'cmpdesc',
                            margin: 5,
                            style: 'background-color: white;',
                            name: 'cmpdesc',
                            fieldLabel: 'Description',
                            hideLabel: true,
                            anchor: '100%'
                        }
                    ]
                },
                {
                    xtype: 'fieldset',
                    height: 350,
                    margin: 2,
                    width: 398,
                    title: 'Company Logo',
                    items: [
                        {
                            xtype: 'form',
                            frame: true,
                            itemId: 'logoform',
                            id: 'logoform',
                            height: 320,
                            width: 375,
                            bodyPadding: 10,
                            preventHeader: true,
                            title: 'My Form',
                            items: [
                                    {
                                        xtype: 'image',
                                        height: 158,
                                        itemId: 'cmplogoimg',
                                        margin: 10,
                                        width: 287,
                                        src:'http://www.sencha.com/img/sencha-large.png'
                                    },
                                    {
                                        xtype: 'filefield',
                                        margin: '10 0 0 15',
                                        width: 296,
                                        name: 'file',
                                        id: 'file',
                                        itemId: 'file',
                                        fieldLabel: 'File',
                                        labelWidth: 50,
                                        msgTarget: 'side',
                                        allowBlank: false,
                                        emptyText: 'Select file',
                                        buttonText: 'Select a File...'
                                    }],

                                dockedItems: [{
                                    xtype: 'toolbar',
                                    dock: 'bottom',
                                    items: [
                                        {
                                            xtype: 'tbfill'
                                        },
                                        {
                                            xtype: 'button',
                                            text: 'Upload',
                                            handler: function() {
                                                var form = this.up('form').getForm();
                                                alert('VALUE IS :'+form.getValues());
                                                if(form.isValid()){
                                                    form.submit({
                                                        url: 'company/UploadFile.action',
                                                        waitMsg: 'Uploading your file...',
                                                        success: function(fp, o) {
                                                            Ext.Msg.alert('Success', 'Your file has been uploaded.');
                                                            Ext.Ajax.request({
                                                              url: 'company/GetImages.action',
                                                              scope: this,
                                                              success: function(response,opts) {
                                                                    console.log('GET IMAGES');
                                                                }
                                                            });
                                                        }
                                                    });
                                                }

                                            }
                                        },
                                        {
                                            xtype: 'tbseparator'
                                        },
                                        {
                                            xtype: 'button',
                                            text: 'Reset',
                                            itemId: 'btn-reset',
                                            action: 'btn-reset'
                                            ,
                                            handler: function() {
                                                this.up('form').getForm().reset();
                                            }
                                        }
                                    ]
                                }]
                        }
                    ]
                }
            ],
            dockedItems: [
                {
                    xtype: 'toolbar',
                    height: 27,
                    width: 804,
                    dock: 'bottom',
                    items: [
                        {
                            xtype: 'tbfill'
                        },
                        {
                            xtype: 'button',
                            text: 'Save',
                            action: 'btn-save-company'
                        },
                        {
                            xtype: 'tbseparator'
                        },
                        {
                            xtype: 'button',
                            text: 'Exit',
                            action: 'btn-exit-company'
                        }
                    ]
                }
            ]
          }
        ]
        });

        me.callParent(arguments);
    }
});

单击网格时执行的我的控制器函数

editCompany: function(grid, no, rowindex,colindex,temp) {  
        alert('EDIT COMPANY BUTTON PRESSED');
        var rec = this.getCompanyDetail().store.getAt(rowindex);
        console.log(rec);
        var actionid = grid.getCellByPosition( {row:rowindex,column:colindex } ).id;    
        this.getCompanyEdit().animateTarget=actionid;
        this.getCompanyEdit().editform=1;
        //this.getCompanyEditForm().getForm().reset();
        this.getCompanyEditForm().loadRecord(rec);                  
        this.getCompanyEdit().show();
    },

我的公司商店是

Ext.define('rms.store.company', {
extend: 'Ext.data.Store',
model: 'rms.model.companyModel',
storeId: 'companyStore',
autoLoad: true,
 proxy: {
    type: 'ajax',
    api: {
        read : 'company/GetCompany.action',
        create : 'company/CreateCompany.action',
        update: 'company/UpdateCompany.action',
        destroy: 'company/DeleteCompany.action'
    },
    reader: {
        type: 'json',
        root: 'companydata',
        totalProperty: 'total',
        successProperty: 'success'

    },
    writer: {
        type: 'json',
        writeAllFields: true,
        encode: true,
        root: 'companydata'
    }
}

});

我的公司模式是

Ext.define('rms.model.companyModel', {
extend: 'Ext.data.Model',
fields : [
          { name: 'id', type: 'int', useNull: true, mapping: 'id'},
          { name: 'cmpname', type: 'string', mapping: 'cmpname'},
          { name: 'cmptitle', type: 'string', mapping: 'cmptitle'},
          { name: 'cmpdesc', type: 'string', mapping: 'cmpdesc'},
          { name: 'cmpfax', type: 'string', mapping: 'cmpfax'},
          { name: 'cmpcontact', type: 'string', mapping: 'cmpcontact'},
          { name: 'cmpwebsite', type: 'string', mapping: 'cmpwebsite'},
          { name: 'cmpemail1', type: 'string', mapping: 'cmpemail1'},
          { name: 'cmpemail2', type: 'string', mapping: 'cmpemail2'},
          { name: 'countryname', type: 'int', mapping: 'country'},
          { name: 'statename', type: 'int', mapping: 'state'},
          { name: 'cityname', type: 'int', mapping: 'city'},
          { name: 'cmplogo', type: 'string', mapping: 'cmplogo'},
          { name: 'cmplogopath', type: 'string', mapping: 'cmplogopath'},
          { name: 'cmpaddress', type: 'string', mapping: 'cmpaddress'},
      ]

});

从服务器响应中,我收到了 countryid、stateid、cityid。但我无法使用收到的 id 设置组合框。 请帮我解决这个问题。

【问题讨论】:

    标签: extjs4 extjs-mvc


    【解决方案1】:

    您的商店“国家/地区”在哪里?它是如何定义的?

    【讨论】:

    • 我更新了我的问题。请建议我一些解决方案,我可以尝试解决我的问题
    • 您在哪里加载组合框的商店?请记住,加载过程是异步的,当您将其他存储值加载到表单时,它仍然可以简单地加载
    • 我更新了我的问题并添加了 companyStore 和 companyModel。请查看并帮助我在 EditWindow 中为国家、州、城市设置组合框
    • 您的国家/州/城市商店很可能未加载。
    • 我有四家商店和公司,国家,州,城市。我的公司商店返回给我要在国家组合框上设置的正确数据,但仍然无法正确设置组合框
    【解决方案2】:

    您希望您的组合框加载所有商店模型的列表以及您要传递的模型,还是只包含您要传递的模型?

    另外,请尝试在每个组合框项中设置属性 queryMode: local 以防万一...

    【讨论】:

    • 我有四个商店 countryStore 用于国家组合,stateStore 用于国家组合,cityStore 用于城市组合,companyStore 用于公司。当我单击公司网格列表时,它会打开 EditCompany 窗口。我从服务器响应中获取我的 json 数据,但仍然无法在我的编辑窗口中设置国家、州和城市的组合框。请建议我一些解决方案,我被困在这里
    • 你试过用queryMode:local设置每个组合吗?
    • 您是否尝试使用queryMode:local 设置每个组合?我还建议您在每个组合框定义中使用store: Ext.StoreManager.Lookup('company') 而不是 store: 'company'
    • 很抱歉,我仍然不明白您是否无法填充组合框,或者是否填充了组合框但您无法选择相应的项目。
    猜你喜欢
    • 1970-01-01
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 2014-02-10
    • 2013-07-28
    • 2012-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多