2012-03-24 3 views
0

У меня есть сводка в моей форме. Первоначально я использовал эту форму для добавления новой информации о компании в мою базу данных.Как установить идентификатор combobox из данных хранилища, полученных в extjs 4

Теперь у меня есть сетка, содержащая информацию о компании, когда я нажимаю на нее на основе запроса Id, и она возвращает полную информацию о фирменном магазине.

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

моего companydata является 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": "[email protected]", 
     "cmpemail2": "[email protected]", 
     "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 
} 

Теперь на его основе я хочу, чтобы установить значение моей формы редактирования. Все значения установлены отлично, только значения combobox не устанавливаются отлично.

моих редактирования кода окно ниже

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. Но я не могу установить combobox с идентификатором, который я получил. Пожалуйста, помогите мне выйти из этой проблемы.

ответ

0

Местонахождение Вашего магазина "страна" и как оно определено?

+0

Я обновил свой вопрос. Пожалуйста, предложите мне какое-то решение, я могу попытаться решить мою проблему. –

+0

Где вы загружаете свои магазины для combobox? Помните, что процедура загрузки является асинхронной, и ее можно просто загружать при загрузке других значений хранилища в форму – sha

+0

У меня было обновление моего вопроса и добавлено фирменное хранилище и компанияModel. Пожалуйста, посмотрите на него и помогите мне установить поле со списком для страны, штата, города в EditWindow. –

0

Вы хотите, чтобы ваши выпадающие списки загружались со списком всех моделей магазинов и того, который вы передаете, или вы хотите, чтобы он содержал только тот, который вы передаете?

Кроме того, попробуйте установить в каждом элементе поле со списком свойство queryMode: local на всякий случай ...

+0

У меня есть четыре магазина countryStore для национальной комбо, stateStore для государственной комбо, cityStore для комбо города и компания для компании. Когда я нажимаю список сетки компании, он открывает окно EditCompany. Я получаю свои данные json от ответа сервера, как указано выше, но до сих пор не могу установить combobox для страны, штата и города в моем окне редактирования. Пожалуйста, предложите мне какое-то решение, которое я застрял здесь –

+0

. Вы пытались установить каждую комбо с 'queryMode: local'? – Agus

+0

Вы пытались установить каждую комбо с 'queryMode: local'? Я бы также предложил вам использовать в каждом определении combobox (это, как я это делаю, и это работает для меня) 'магазин: Ext.StoreManager.Lookup ('компания')' вместо 'магазин: 'компания'' – Agus

Смежные вопросы