PDA

View Full Version : Select and store not working



Steve Lewis
18 Sep 2010, 12:54 PM
Hi,

I'm trying to populate a select form item from a store linked to a json data source. I seem to be able to load the data correctly (from json source) but can't seem to populate the select item. The setOptions gets called on onDataChanged callback but the select control never gets the appropriate values (I'm using 0.93 version of the library).

Any obvious problems?

Ext.regModel('Market', {
fields: [
{ name: 'value', mapping: 'id' },
{ name: 'data', mapping: 'name' }
]
});

this.marketStore = new Ext.data.Store({
model: 'Market',
proxy: {
type: 'scripttag',
url: CONFIG.api_host + "/api/consumer/markets/",
reader: {
type: 'json',
idProperty: 'id'
}
},
autoLoad: true,
listeners: {
scope: this,
single: true
});

{
xtype: 'select',
name: 'market',
store: this.marketStore,
]
}
];

evant
19 Sep 2010, 7:34 PM
Based on 0.95.



Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,

onReady: function(){
var form = new Ext.form.FormPanel({
fullscreen: true,
items: [{
xtype: 'select',
displayField: 'name',
valueField: 'value',
store: new Ext.data.Store({
data: [{
name: 'Australia',
value: 1
}, {
name: 'USA',
value: 2
}],
fields: ['name', 'value']
}),
listeners: {
select: function(select, value){
var other = form.items.last(),
store = other.store;
store.removeAll();
if(value == 1){
store.loadData([{
name: 'Brisbane',
value: 1
},{
name: 'Melbourne',
value: 2
},{
name: 'Sydney',
value: 3
}]);
other.setValue(1);
}else{
store.loadData([{
name: 'Los Angeles',
value: 1
},{
name: 'New York',
value: 2
},{
name: 'San Francisco',
value: 3
}]);
}
other.setValue(1);
}
}
}, {
xtype: 'select',
displayField: 'name',
valueField: 'value',
store: new Ext.data.Store({
data: [{
name: 'foo',
value: 1
}, {
name: 'bar',
value: 2
}],
fields: ['name', 'value']
})
}]
});
}
});

Steve Lewis
20 Sep 2010, 1:21 PM
Thanks Evan,

Should I assume this won't work in 0.93 then? (I tried upgrading but a bunch of things broke so need to sort thru that).

evant
20 Sep 2010, 3:49 PM
I haven't tried it, left as an exercise for the reader ;)