ExtJS字符串到Combobox [英] ExtJS String to Combobox
问题描述
我有一个php文件返回一个这样的字符串
I have a php file that returns a string like this
["item1","item2","item3","item4"]
我需要使用ExtJS创建一个组合框。选项必须是4个选项的项目。如果php链接 items.php
,我该如何做。为了使事情清楚我需要组合框displayField
和 valueField
有相同的值,如 item1
将是 displayField
和 valueField
。提前感谢!
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!
该字符串不是Json格式的,我想它是数组存储。
P.S. the string is not Json formatted, I guess it's array store.
推荐答案
首先,我想你必须修改你的php脚本它至少返回字符串 [[item1],[item2],[item3],[item4]]
。否则你必须创建自己的extjs阅读器或重写Ext.data.reader.Array.read方法。
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'
}
}
}
第三,你的组合配置应该看起来像这样: / p>
Thirdly, your combo config should look like this:
Ext.create('Ext.form.ComboBox', {
store: store,
displayField: 'item',
valueField: 'item'
});
你决定使用你的原始php脚本无论如何你可以看看如何定义自己的阅读器(讨论了json阅读器,但你可以弄清楚如何在数组阅读器中实现该代码)
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)
这篇关于ExtJS字符串到Combobox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!