2017-10-17 115 views
0

首先,对不起我的英文。 毫无疑问,在写作之前,我搜索了很多,但没有成功。ExtJS 3.4 - comboBox linked

我有两个链接的组合框。 第一个:

var groupe_cible = new Ext.data.JsonStore({ 
    url : "data/fonctions_data.php?pFunction=access_group&user_id=" + p, 
    fields: [ 
     {name: 'value', mapping: 'value', type: 'string'}, 
     {name: 'id', mapping: 'id_group', type: 'int'} 
    ], 
    autoLoad : true 

}); 

JSON结果:

[{"value":"fibre","id_group":1},{"value":"eau_pluviale","id_group":2}] 

第二种:

var param_cible = new Ext.data.ArrayStore({ 
//pruneModifiedRecords: true, 
    autoDestroy: true, 
    url : "data/fonctions_data.php?pFunction=access_param&user_id=" + p, 
    fields: [ 
      {name: 'value', mapping: 'value', type: 'string'}, 
      {name: 'id', mapping: 'id', type: 'int'}, 
      {name: 'groupcode', mapping: 'groupcode', type: 'int'} 
    ], 
     autoLoad : true 
}); 

JSON结果:

[{"value":"vias","id":2,"groupcode":2},{"value":"cahm","id":1,"groupcode":1},{"value":"agde","id":2,"groupcode":2}] 

的链接:id_group = groupcode

组合框=

var groupeCombo = new Ext.form.ComboBox({ 
    id: "contenutypetraitementdict", 
    x: 5, 
    y: 55, 
    width : 150, 
    store: groupe_cible, 
    emptyText:'Choisir le type de traitement', 
    valueField: 'id', 
    displayField: 'value', 
    typeAhead: false, 
    editable: false, 
    mode: 'local', 
    allowBlank:false, 
    forceSelection: true, 
    border: false, 
    triggerAction: 'all', 
    //lastQuery: '', 
    selectOnFocus:true, 
    listeners: { 
     select : function(cmb, group, idx) { 
      autosStore = paramCombo.getStore(); 
      paramCombo.clearValue(); 
      autosStore.clearFilter(); 
      autosStore.filterBy(function(item) { 
       var paramCode = item.get('groupcode'); 
       var selected = (paramCode === group.data.id); 
       return selected; 
      }); 
      paramCombo.enable(); 
     } 
    } 
}); 

var paramCombo = new Ext.form.ComboBox({ 
    id: "contenutypetraitementdictparam", 
    x: 5, 
    y: 85, 
    width : 150, 
    store: param_cible, 
    emptyText:'Choisir le type de traitement', 
    allowBlank:false, 
    valueField: 'id', 
    displayField: 'value', 
    //border: false, 
    typeAhead: false, 
    editable: false, 
    mode: 'local', 
    forceSelection: true, 
    triggerAction: 'all', 
    lastQuery: '', 
    selectOnFocus:true 
}); 

然后,两个组合框是位于FormPanel。 作品链接,但我有一个问题:see attachment 下拉列表链接,但总有一个默认值。 要举例说明,如果我点击“agde”,第二项,最后我总是有第一个值(“过孔”)。

问题很难解决(Firebug没有问题)。

谢谢。

回答

1

尝试通过指定的属性记录使用filter

过滤。或者,传递一组过滤器选项以通过多个属性进行过滤。单个过滤器示例:store.filter('name','Ed',true,true)

我已经创建了一个sencha fiddle演示,希望这可以帮助您解决问题或实现您的要求。

Ext.onReady(function() { 

    //groupe_cible store 
    var groupe_cible = new Ext.data.JsonStore({ 
     fields: [{ 
      name: 'value', 
      mapping: 'value', 
      type: 'string' 
     }, { 
      name: 'id', 
      mapping: 'id_group', 
      type: 'int' 
     }], 
     type: 'ajax', 
     url: 'groupe_cible.json', 
     type: 'json', 
     root: 'data', 
     autoLoad: true 
    }); 

    //param_cible store 
    var param_cible = new Ext.data.JsonStore({ 
     fields: [{ 
      name: 'value', 
      mapping: 'value', 
      type: 'string' 
     }, { 
      name: 'id', 
      mapping: 'id', 
      type: 'int' 
     }, { 
      name: 'groupcode', 
      mapping: 'groupcode', 
      type: 'int' 
     }], 
     type: 'ajax', 
     url: 'param_cible.json', 
     type: 'json', 
     root: 'data', 
     autoLoad: true 
    }); 

    //groupe_cible combo 
    var item1 = new Ext.form.ComboBox({ 
     mode: 'local', 
     triggerAction: 'all', 
     listClass: 'comboalign', 
     typeAhead: true, 
     forceSelection: true, 
     selectOnFocus: true, 
     displayField: 'value', 
     emptyText: 'Select groupe_cible', 
     valueField: 'id_group', 
     store: groupe_cible, 
     listeners: { 
      select: function (combo, record) { 
       var param_cible = Ext.getCmp('param_cible'), 
        store = param_cible.getStore(); 
       param_cible.setDisabled(false).setValue(''); 
       store.clearFilter(); 
       store.filter('groupcode', combo.getValue()); 

       // You can also use getValue method of Combo 
       // store.filter('groupcode', record[0].get('id')); 
      } 
     } 
    }); 

    //param_cible combo 
    var item2 = new Ext.form.ComboBox({ 
     mode: 'local', 
     triggerAction: 'all', 
     listClass: 'comboalign', 
     typeAhead: true, 
     forceSelection: true, 
     selectOnFocus: true, 
     id: 'param_cible', 
     disabled: true, //initially param cibil will disable 
     emptyText: 'Select param_cible', 
     displayField: 'value', 
     valueField: 'id', 
     store: param_cible 
    }); 

    //create panel with both combo 
    new Ext.Panel({ 
     width: 250, 
     renderTo: document.body, 
     title: 'Filter in Combo on basis of selection', 
     items: [item1, item2] 
    }); 

});