ExtJS String to Combobox

元气小坏坏 提交于 2019-12-25 03:48:28

问题


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.


回答1:


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)



来源:https://stackoverflow.com/questions/6767744/extjs-string-to-combobox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!