View Full Version : looking for a selectfield example to select one specific option item

29 Nov 2011, 1:51 AM
Hi, I'm looking for an example, where i can fill a selectfield with json data and after that I would like to set the selected value to a specific value from the json exported (field: selected) data.

my json data looks like this

{"userID": "2", "benutzername": "Franz Mustermann", "selected": 1},
{userID": "1", "benutzername": "Susi Mustermann","selected": 0}

I'm familiar with the loading process but I have no idear how I can selected a specific option item.

29 Nov 2011, 4:09 AM
Know I found one solutions, but I hope there is one easier way to do this, because what happend if I have more than one selectfields, like 10 ?

In the formPanel I use a listener to look on the activate event, if this happend, I loop over the userStore model and look for the selected marker, if this match, I save the userID and break the loop, after that I set the value with the setValues method.

listeners: {
activate: function(){

// selected Item für zugewiesen an
var selectedID = 0;
for (var i=0; i<sim.stores.userStore.data.length; i++){

//console.log("test "+sim.stores.userStore.data.items[i].data.benutzername);

if(sim.stores.userStore.data.items[i].data.selected == 1)
selectedID = sim.stores.userStore.data.items[i].data.userID;