Data is not displaying in multiselect after loading data from store in extjs
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.
You have missed out the field mapping properties for your multiselect. You will have to add:
displayField: 'text',
valueField: 'value'
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:
{"rows": [{"text" : "012345","value": "012345"},{"text": "012346","value": "012346"},{"text": "01234567","value": "01234567"},{"text": "546747","value": "546747"}],"num": 4}
To do so, you will have to go with a JsonStore rather than Array. Is there any particular reason you choose ArrayStore?
You either have to remove root: 'data',
from store config or modify server response so that it would look like:
{data: [['012345', '012345'], ['012346', '012346'], /* ... */ ]}
精彩评论