Json EXT JS组合框不重新加载数据
我遇到了一个问题-在我的网格中,我链接了两个组合框(乡村和城镇)。我正在选择country并正确获取所有城镇(JSON),但在下一次更改country组合框时,我的城镇组合框不会重新加载。我做错了什么? 这是我的密码Json EXT JS组合框不重新加载数据,json,combobox,extjs,Json,Combobox,Extjs,我遇到了一个问题-在我的网格中,我链接了两个组合框(乡村和城镇)。我正在选择country并正确获取所有城镇(JSON),但在下一次更改country组合框时,我的城镇组合框不会重新加载。我做错了什么? 这是我的密码 Ext.onReady(function(){ Ext.QuickTips.init(); var Organization = Ext.data.Record.create([{ name: 'name_ru', type: 'string' }, {
Ext.onReady(function(){
Ext.QuickTips.init();
var Organization = Ext.data.Record.create([{
name: 'name_ru',
type: 'string'
}, {
name: 'name_en',
type: 'string'
}, {
name: 'type',
type: 'string'
},{
name: 'country',
type: 'string'
},{
name: 'town',
type: 'string'
}]);
var Town = Ext.data.Record.create([{
name: 'id',
type: 'integer'
}, {
name: 'name',
type: 'string'
}]);
Ext.namespace("Ext.ux");
Ext.ux.comboBoxRenderer = function(combo) {
return function(value) {
var idx = combo.store.find(combo.valueField, value);
var rec = combo.store.getAt(idx);
return rec.get(combo.displayField);
};
}
var proxy1 = new Ext.data.HttpProxy({
url: 'emp2.php'
});
var writer = new Ext.data.JsonWriter({
encode: true // В документации сказано если вы будете использовать rest то этот флаг нужно выставить в false
});
var store4 = new Ext.data.GroupingStore({
proxy: proxy1,
reader: new Ext.data.JsonReader({root: 'org',totalProperty: 6, id: 'name_ru'},[{name: 'name_ru'},
{name: 'name_en'},
{name: 'type'},
{name: 'country'},
{name: 'town'}]),
writer:writer,
// restful: true,
root: 'emp',
sortInfo: {field: 'name_ru', direction: 'ASC'}
});
getData = function(_req,_forVal)
{
var myStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'include/getRFB.php?'+_req+'='+_forVal,
method: 'POST',
totalProperty: 6
}),
reader: new Ext.data.JsonReader({
id: 'id',
root:'town'
},[
{name: 'id', mapping: 'id'},
{name: 'name', mapping: 'name'}
]),
remoteSort: true
});
// Ext.Msg.alert('Hello this is the title', myStore);
myStore.load();
return myStore;
}
var townStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'include/getRFB.php?test=true',
method: 'POST'
}),
reader: new Ext.data.JsonReader({
id: 'id',
root:'test',
totalProperty: 6
},[
{name: 'id', mapping: 'id'},
{name: 'name', mapping: 'name'}
]),
remoteSort: true
});
var countryStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'include/getRFB.php?country=true',
method: 'POST'
}),
reader: new Ext.data.JsonReader({
id: 'id',
root:'country',
totalProperty: 6
},[
{name: 'id', mapping: 'id'},
{name: 'name', mapping: 'name'},
{name: 'alpha2', mapping: 'alpha2'},
{name: 'alpha3', mapping: 'alpha3'},
{name: 'iso', mapping: 'iso'}
]),
remoteSort: true
});
var orgTypeStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'include/getRFB.php?orgtype=true',
method: 'POST'
}),
reader: new Ext.data.JsonReader({
id: 'id',
root:'org_type',
totalProperty: 6
},[
{name: 'id', mapping: 'id'},
{name: 'name', mapping: 'name'}
]),
remoteSort: true
});
var comboTown = new Ext.form.ComboBox({
store:townStore,
fieldLabel: 'Town',
displayField: 'name',
valueField: 'id',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
name : 'town1',
id : 'town1',
emptyText : 'Выберите город...',
hiddenName : 'town_name',
width : 250,
anchor:'-50'
});
var combo1 = new Ext.form.ComboBox({
store:countryStore,
fieldLabel: 'Country',
displayField: 'name',
valueField: 'id',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
name : 'country1',
id : 'country1',
emptyText : 'Выберите страну...',
hiddenName : 'country_name',
width : 250,
anchor:'-50',
listeners : {
select: function(f,r,i){
// f=formfield r=data rec of selected combo item i=index num of clicked item
_forVal = this.getValue(); //get selected value of this comboBox
//comboTown.store.clearFilter();
comboTown.store =getData('countryT',_forVal); //call function tht load store
comboTown.displayField = 'name';
comboTown.reset();
}
}
});
var comboOrgType = new Ext.form.ComboBox({
store:orgTypeStore,
fieldLabel: 'Name',
displayField: 'name',
valueField: 'id',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus: true,
name : 'orgtype1',
id : 'orgtype1',
allowBlank : false,
emptyText : 'Выберите тип...',
hiddenName : 'name',
width : 250,
anchor:'-50'
});
countryStore.load();
orgTypeStore.load();
townStore.load();
var editor = new Ext.ux.grid.RowEditor({
saveText: 'Обновить'
});
store4.load();
var grid = new Ext.grid.GridPanel({
store: store4,
width: 600,
region:'center',
margins: '0 5 5 5',
autoExpandColumn: 'name',
plugins: [editor],
view: new Ext.grid.GroupingView({
markDirty: false
}),
tbar: [{
iconCls: 'icon-user-add',
text: 'Добавить организацию',
handler: function(){
var e = new Organization({
name_ru: 'Наименование организации ру',
name_en: 'Наименование организации анг',
type: '1',
country: '2',
town: '2'
});
editor.stopEditing();
store4.insert(0, e);
grid.getView().refresh();
grid.getSelectionModel().selectRow(0);
editor.startEditing(0);
}
},{
ref: '../removeBtn',
iconCls: 'icon-user-delete',
text: 'Удалить организацию',
disabled: true,
handler: function(){
editor.stopEditing();
var s = grid.getSelectionModel().getSelections();
for(var i = 0, r; r = s[i]; i++){
store4.remove(r);
}
}
}],
columns: [
new Ext.grid.RowNumberer(),
{
id: 'name',
header: 'Название организации(рус)',
dataIndex: 'name_ru',
width: 200,
sortable: true,
editor: {
xtype: 'textfield',
allowBlank: false
}
},{
header: 'Название организации(eng)',
dataIndex: 'name_en',
width: 195,
sortable: true,
editor: {
xtype: 'textfield',
allowBlank: false,
}
},{
header: 'Тип',
dataIndex: 'type',
width: 85,
sortable: true,
editor: comboOrgType,
renderer: Ext.ux.comboBoxRenderer(comboOrgType)
},{
header: 'Страна',
dataIndex: 'country',
width: 90,
sortable: true,
editor: combo1,
renderer: Ext.ux.comboBoxRenderer(combo1)
},{
header: 'Город',
dataIndex: 'town',
width: 90,
sortable: true,
editor: comboTown,
renderer: Ext.ux.comboBoxRenderer(comboTown)
}]
});
//Ext.Msg.alert('您好,这是标题',store4.getCount())
var布局=新的外部面板({
标题:“СПззззззз”,
布局:“边框”,
布局配置:{
栏目:1
},
宽度:720,
身高:600,
项目:[表格]
});
layout.render(Ext.get('editor-grid'));
grid.getSelectionModel().on('selectionchange',函数(sm){
grid.removeBtn.setDisabled(sm.getCount()<1);
});
}))
谢谢 我试试看:)
在SelectListenerinCombo1(国家/地区)中,使用getData(…)方法设置存储。getData(…)方法创建一个新的存储,该存储被加载然后返回。我记得曾经遇到过一些类似的问题,解决方法可能是首先将存储分配给组合框,然后加载存储 就我所见,您使用getData(…)只是为了为town组合创建一个新的存储。为什么不更新城镇商店的参数,然后重新加载
希望有帮助:)好的,我扔了它,然后从这里开始做所有的事情-
它是有效的。这就是我所需要的。谢谢。我现在正在尝试-在侦听器处加载数据:comboTown.store.reload({params:{'countryT':\u forVal}});在firebug数据加载但组合框未加载时:(“将存储分配给组合框,然后加载存储。”也不要修复ot:(
var layout = new Ext.Panel({
title: 'Список организаций',
layout: 'border',
layoutConfig: {
columns: 1
},
width:720,
height: 600,
items: [grid]
});
layout.render(Ext.get('editor-grid'));
grid.getSelectionModel().on('selectionchange', function(sm){
grid.removeBtn.setDisabled(sm.getCount() < 1);
});