首先,对不起我的英语。 毫无疑问,在写作之前,我搜索了很多,但没有成功。
我有两个comboBox链接。 第一个:
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
ComboBox =
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
});
然后两个comboBox都在FormPanel中。 该链接有效,但我遇到了问题:see attachment 下拉列表已关联,但始终存在默认值。 要按照示例,如果我点击值" agde" ,第二项,最后,我总是有第一个值(" vias& #34; )
问题很难解决(Firebug没问题)。
谢谢。
答案 0 :(得分: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]
});
});