从 extjs 中的存储加载数据后,数据未显示在多选中
我已经尝试了两天但无法找到解决方案。我要做的是将数据远程加载到存储中,这是我的代码:
var ds = Ext.create('Ext.data.ArrayStore', {
proxy: {
type: 'ajax',
url : './index.php/firewall/loadRules',
},
fields: ['value','text'],
totalProperty: 'num',
sortInfo: {
field: 'value',
direction: 'ASC'
}
});
ds.load();
在此之后将此存储分配给多选组件,其代码如下:
var form_number_list = Ext.create('Ext.form.Panel', {
border: false,
bodyPadding: 5,
id: 'form_number_list',
width: '35%',
height: '100%',
flex: 3,
items: [{
anchor: '93%',
xtype: 'multiselect',
msgTarget: 'side',
name: 'multiselect',
id: 'fire_select',
allowBlank: false,
minSelections: 1,
maxSelections: 1,
store: ds
}]
});
ajax 调用返回此值:
[['012345', '012345'], ['012346', '012346'], ['01234567', '01234567'], ['546747', '546747'], ['54663', '54663'], ['546638', '546638'], ['46767638', '46767638'], ['63568545868', '63568545868'], ['6368688', '6368688'], ['35468488', '35468488'], ['84584845', '84584845'], ['56345738', '56345738'], ['533478', '533478'], ['583477', '583477'], ['563457548', '563457548'], ['53755438', '53755438'], ['53657648', '53657648'], ['5367764', '5367764'], ['563673673', '563673673'], ['5436638', '5436638'], ['46363773', '46363773'],]
现在在浏览器中,多选框正在加载这么多项目,但它们的值没有显示,我的意思是所有项目都是空项目。在 Firebug 中,我可以看到所有项目的空“li”标签。
I have been trying this from two days but unable to found a solution for this. What i am tying to do is remotely loading the data into the store here is my code for that:
var ds = Ext.create('Ext.data.ArrayStore', {
proxy: {
type: 'ajax',
url : './index.php/firewall/loadRules',
},
fields: ['value','text'],
totalProperty: 'num',
sortInfo: {
field: 'value',
direction: 'ASC'
}
});
ds.load();
After this assigning this store to multiselect component and the codes for that is here:
var form_number_list = Ext.create('Ext.form.Panel', {
border: false,
bodyPadding: 5,
id: 'form_number_list',
width: '35%',
height: '100%',
flex: 3,
items: [{
anchor: '93%',
xtype: 'multiselect',
msgTarget: 'side',
name: 'multiselect',
id: 'fire_select',
allowBlank: false,
minSelections: 1,
maxSelections: 1,
store: ds
}]
});
The ajax call is returning this value:
[['012345', '012345'], ['012346', '012346'], ['01234567', '01234567'], ['546747', '546747'], ['54663', '54663'], ['546638', '546638'], ['46767638', '46767638'], ['63568545868', '63568545868'], ['6368688', '6368688'], ['35468488', '35468488'], ['84584845', '84584845'], ['56345738', '56345738'], ['533478', '533478'], ['583477', '583477'], ['563457548', '563457548'], ['53755438', '53755438'], ['53657648', '53657648'], ['5367764', '5367764'], ['563673673', '563673673'], ['5436638', '5436638'], ['46363773', '46363773'],]
Now after this in the browser, the multiselect box is getting this many item loaded but their values are not getting displayed i mean all items are empty items. In firebug i can see empty "li" tags for all the items.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您错过了多选的字段映射属性。您必须将: 添加
到您的多选中。另外,请记住,最好返回正确的 json 而不是数组,因为您似乎正在使用总属性。您可以按如下方式使用 json:
为此,您必须使用 JsonStore 而不是 Array。您选择 ArrayStore 有什么特别的原因吗?
You have missed out the field mapping properties for your multiselect. You will have to add:
to your multiselect. Also, keep in mind that it is best to return a proper json rather than an array because, you seems to be making use of total property. You can use json as follows:
To do so, you will have to go with a JsonStore rather than Array. Is there any particular reason you choose ArrayStore?
您必须从存储配置中删除
root: 'data',
或修改服务器响应,使其看起来像:You either have to remove
root: 'data',
from store config or modify server response so that it would look like: