ExtJS String to Combobox
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
a开发者_运维百科nd 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.
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)
精彩评论