2016-05-02 39 views
0

是否需要用數據填充組合框的數據存儲?在看過它的文檔之後,我想確認,因爲我是ExtJS的新手。Combobox需要數據存儲嗎?

選擇列表的選項從任何Ext.data.Store(包括遠程存儲)中填充。商店中的數據項分別通過valueField和displayField配置映射到每個選項的顯示文本和備份值。 - http://docs.sencha.com/extjs/4.0.7/#!/api/Ext.form.field.ComboBox

我在窗體中有幾個組合框;所有這些將包含不同的選項。這是否意味着我將不得不爲每個組合框創建一個數據存儲?

Ext.onReady(function() { 
    console.clear(); 
    Ext.create('Ext.data.Store', { 
     storeId: 'confiurationDetailsStoreForRead', 
     fields: ['value', 'name'], 
     data: [{ 
      "value": "72001", 
      "name": "Enabled" 
     }, { 
      "value": "72002", 
      "name": "Disabled" 
     }, { 
      "value": "72003", 
      "name": "Required" 
     }] 
    }); 
    var configurationDetailsPanel = Ext.create({ 
     xtype: 'form', 
     url: '/employeeSearchResult', 
     items: [{ 
      xtype: 'combobox', 
      fieldLabel: 'Config Type', 
      store: Ext.getStore('confiurationDetailsStoreForRead'), 
      queryMode: 'local', 
      displayField: 'name', 
      valueField: 'value' 
     }], 

     buttonAlign: 'left', 
     buttons: [{ 
      text: 'Search', 
      handler: function() { 
       console.log('Search Pressed'); 
      } 
     }, { 
      text: 'Reset', 
      handler: function() { 
       this.up('form').getForm().reset(); 
      } 
     }] 
    }); 

    //Main Container 
    Ext.create({ 
     xtype: 'panel', 
     renderTo: Ext.getBody(), 
     defaultType: 'button', 
     layout: { 
      type: 'vbox', 
      align: 'stretch' 
     }, 
     items: [configurationDetailsPanel] 
    }); 
}); 

上面的代碼是我的窗體中一個組合框的示例。我想知道是否有任何方法可以將數據正確地放入combox配置中(而不是創建一個存儲,然後在配置中引用該存儲)?或者是我在上面的代碼中使用的唯一方法?

在此先感謝。

回答

1

是的!你可以把商店對進入組合框:

   { 
       xtype: 'combobox', 
       fieldLabel: 'Config Type', 
       displayField: 'name', 
       queryMode: 'local', 
       store: { 
        fields: [ 
         'value', 
         'name' 
        ], 
        data: [ 
         { 
          value: '72001', 
          name: 'Enabled' 
         }, 
         { 
          value: '72002', 
          name: 'Disabled' 
         }, 
         { 
          value: '72003', 
          name: 'Required' 
         } 
        ] 
       }, 
       valueField: 'value' 
      } 
1

,它可以像這個問題,以及

{ 
     xtype: 'combobox', 
     fieldLabel: 'Config Type', 
     queryMode: 'local', 
     store: [ 
      [ '72001', 'Enabled' ], 
      [ '72002', 'Disabled' ], 
      [ '72003', 'Required' ] 
     ] 
    } 
完成
相關問題