2017-08-29 85 views
0

我有兩個組合框,我希望combox(b)基於從combobox A選擇的值被禁用(我應該看看它的存儲數據查找記錄和如果記錄參數(arsubOpen)的值爲1,那麼只有我應該啓用組合框B)。爲此,我添加了一個類似於A的商店,並添加了一個過濾器來過濾僅包含arsubOpen 1的記錄。現在,我如何根據這些商店記錄啓用它們。如何禁用基於viewModel存儲returnrd數據的組件extjs

Test fiddle

回答

0

你可以聽change事件,並要啓用第二個組合框的任意值比較新值:根據您自己的

{ 
    xtype: 'combobox', 
    anchor: '100%', 
    displayField: 'description', 
    valueField: 'adjustmentTypeId', 
    fieldLabel: 'A', 
    // lastQuery: '' to disable store loading a second time on trigger click 
    lastQuery: '', 
    bind: { 
     store: '{a}' 
    }, 
    listeners: { 
     change: function(combo, value) { 
      // Logging a value to console - remove this code 
      console.log(value); 

      var store = combo.getStore(); 
      var record = store.findRecord(combo.valueField, value) 
      var arsubOpen = record.get('arsubOpen'); 
      // Condition for enabling here 
      var shouldEnable = arsubOpen === 1; 

      var form = combo.up('form'); 
      var basicForm = form.getForm(); 
      // 'bField' si the name of the B combobox field 
      var bCombo = basicForm.findField('bField'); 
      bCombo.setDisabled(!shouldEnable); 
     } 
    } 
}, 
{ 
    xtype: 'combobox', 
    anchor: '100%', 
    // Field name to use for form submitting and finding the field 
    name: 'bField', 
    displayField: 'description', 
    valueField: 'arOnlySubCategoryId', 
    fieldLabel: 'B', 
    // lastQuery: '' to disable store loading a second time on trigger click 
    lastQuery: '', 
    bind: { 
     disabled: 'disableB', 
     store: '{B}' 
    } 
} 

一個fiddle

我投入了lastQuery: ''配置,以禁止第二次加載存儲在觸發器點擊,這可能非常煩人,並花了我很多小時才能找出解決方案。

+0

感謝marathy,但這裏的關鍵是基於同一記錄中的其他參數啓用和禁用。例如:\t「arsubOpen」:「0」{「adjustTypeId」:7,「type」:「M」,「invoiceType」:「M」,「description」:「其他」,「createUserId」:「9」 createDateTime「:1412711611023,」updateUserId「:」21「,」updateDateTime「:1475603316810,」invoiceCode「:」MS「,」categoryCode「:」MS「,」active「:true,」arsubOpen「:」0「是雜項的記錄。所以我需要檢查這個記錄,看看「arsubOpen」是0還是1,如果是1,我需要啓用B – Sweety

+0

您是否將組合框用於其他任何東西?如果沒有,你可以將'valueField'定義爲''arsubOpen''。如果是的話,你可以使用'var record = combo.getStore()。findRecord(combo.valueField,value)'。 – MarthyM

+0

我正要發表相同的感謝Marthy – Sweety

相關問題