PDA

View Full Version : store into a Select field



elienajem22
15 Mar 2012, 10:41 AM
Any help plz

I'm trying to load a store into a Select field in sencha


dataStore:

Ext.regModel('countries', {
fields: ['label','value']
});


var country_store = new Ext.data.Store({
model: "countries",
id:'country_store',
data:[],
proxy: {
type: 'ajax',
url : 'mobile.php',
reader: {
type: 'json',
root: 'countries'
},
autoLoad: true
}
});

mobile.php return:


{"countries":[{"label":"16","value":"China"},{"label":"14","value":"Austria"},{"label":"17","value":"Cuba"}]}



select field:
{
xtype: 'selectfield',
name : 'bycountry',
label: 'Country',
valueField : 'value',
displayField : 'label',
id:'bycountry',
store : country_store
}

mitchellsimoens
15 Mar 2012, 11:31 AM
Remove the data config and move the autoLoad config from the proxy to the store.

elienajem22
15 Mar 2012, 12:47 PM
hello again, i removed the data config and i moved the autoLoad config from the proxy to the store.
same problem, the select field is empty.


Ext.regModel('countries', {
fields: ['label','value']

});


var country_store = new Ext.data.Store({
model: "countries",
id:'country_store',
proxy: {
type: 'ajax',
url : 'mobile.php',
reader: {
type: 'json',
root: 'countries'
},
},
autoLoad: true
});



mobile.php return

{"countries":[{"label":"16","value":"China"},{"label":"14","value":"Austria"},{"label":"17","value":"Cuba"},{"label":"20","value":"Egypt"},{"label":"19","value":"Czech Republic"},{"label":"18","value":"Cyprus"},{"label":"15","value":"Brazil"}]}php code mobile.php

$responses = array();
while($row = mysql_fetch_array($sql)){
$response = array(
"label" => $row["id"],
"value" => $row["country"]
);
$responses[] = $response;}


echo '{"countries":'.json_encode($responses).'}';