tags:

views:

358

answers:

1

I'm having issues while populating a combobox using DirectStore, the combobox is as follow:

this.Combo = new Ext.form.ComboBox({
        fieldLabel: "Name",
        editable: false,
        triggerAction: 'all',
        mode: 'remote',
        store: new Ext.data.DirectStore({
            reader: new Ext.data.JsonReader({
                successProperty: 'success',
                idProperty: 'name',
                root: 'data',
                fields: [ 'name' ]
            }),
            autoLoad: true,
            api: { read: SS.MyApi.getNames }
        }),
        valueField: 'name',
        displayField: 'name'
    });

The returned json is:

[{"type":"rpc","tid":7,"action":"MyApi","method":"getNames","result":{"success":true,"data":{"name":["name1","name2","name3"]}}}]

And the c# code that generates the json

[DirectMethod]
public JObject getNames()
{
        List<string> names = new List<string>();
  names.Add("name1");
  names.Add("name2");
  names.Add("name3");

  JObject data = new JObject();
  data.Add(new JProperty("name", names));
        return  new JObject(
                            new JProperty("success", true),
                            new JProperty("data", data)
                    );
}

The combobox is showing only one entry with "name1,name2,name3". How can i have one entry per name? Thanks in advance!

A: 

your returned json tells the combobox exactly what to do

"data":{"name":["name1","name2","name3"]}

i only has 1 field (name) in data and this has the value name1, name2, name3 your json has to look more like this:

data : [
   {
      name : "name1"
   }, {
      name : "name2"
   }, {
      name : "name3"
   }
]
Nexum
Great thanks. Instead of List<string> I should return a List<Dictionary<string, object>>. It's working now
skinssay