从 extjs 中的存储加载数据后,数据未显示在多选中

发布于 2024-12-02 20:54:34 字数 1676 浏览 0 评论 0原文

我已经尝试了两天但无法找到解决方案。我要做的是将数据远程加载到存储中,这是我的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

好菇凉咱不稀罕他 2024-12-09 20:54:34

您错过了多选的字段映射属性。您必须将: 添加

displayField: 'text',
valueField: 'value'

到您的多选中。另外,请记住,最好返回正确的 json 而不是数组,因为您似乎正在使用总属性。您可以按如下方式使用 json:

{"rows": [{"text" : "012345","value": "012345"},{"text": "012346","value": "012346"},{"text": "01234567","value": "01234567"},{"text": "546747","value": "546747"}],"num": 4}

为此,您必须使用 JsonStore 而不是 Array。您选择 ArrayStore 有什么特别的原因吗?

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?

说谎友 2024-12-09 20:54:34

您必须从存储配置中删除 root: 'data', 或修改服务器响应,使其看起来像:

{data: [['012345', '012345'], ['012346', '012346'], /* ... */ ]}

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'], /* ... */ ]}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文