0

I have a php file that returns a string like this

["item1","item2","item3","item4"]

I need to create a combobox with ExtJS. The options must be the items like 4 options. How would I do this if the php link is items.php. Just to make things clear I need the combobox displayField and valueField have the same values, like the item1 will be the displayField and the valueField. Thanks in advance!

P.S. the string is not Json formatted, I guess it's array store.

Arpit
  • 6,212
  • 8
  • 38
  • 69
Grigor
  • 4,139
  • 10
  • 41
  • 79

1 Answers1

4

Firstly, I think you have to modify your php script so that it returns string at least like this [["item1"],["item2"],["item3"],["item4"]]. Otherwise you will have to create your own extjs reader or override Ext.data.reader.Array.read method.

Secondly, your store should look like this:

var store = Ext.create('Ext.data.Store', {
  fields: ['item'],
  proxy: {
    type: 'ajax',
    url: '/items.php',
    reader: {
      type: 'array'
    }
  }
}

Thirdly, your combo config should look like this:

Ext.create('Ext.form.ComboBox', {
  store: store,
  displayField: 'item',
  valueField: 'item'
});

If you decide to use your original php script anyway you can take a look at how to define your own reader (There is json reader discussed, but you can figure out how to implement that code in your array reader)

Community
  • 1
  • 1
Molecular Man
  • 22,277
  • 3
  • 72
  • 89
  • I'd add that the array does need to be JSON-formatted (it looks like it is from the example) and that it's [bad practice to return top-level arrays](http://stackoverflow.com/questions/3833299/can-an-array-be-top-level-json-text#answer-3833393) as an HTTP response. – jd. Jul 21 '11 at 07:15
  • To just let you know how I did this, I created a function with javascript that returns the string, then used substr and edited the string to the format I wanted, it works fine now, thanks for everyone's help. :) It's really nice knowing people care and help. – Grigor Jul 21 '11 at 18:18