【问题标题】:Pagination is not updating the view when the next button is clicked单击下一个按钮时,分页不会更新视图
【发布时间】:2017-09-27 13:50:31
【问题描述】:

总行数在分页中正确显示,但在单击下一个按钮时分页未更新视图。

我是 Sencha 的新手。在 Mysql 中,我返回所有行。这样我就可以限制在客户端。如果我限制后端的行,我不能在客户端拥有所有的行。

查看:List.js

/*** This view is an example list of people.
     */



Ext.define('CRUD.view.main.List', {
            extend: 'Ext.grid.Panel',
            xtype: 'home',
            requires: [
                'CRUD.store.Personnel'
            ],

            title: 'Heroes',
            plugins: [
                Ext.create('Ext.grid.plugin.CellEditing', {
                    clicksToEdit: 1
                })
            ],
            layout: 'fit',
            fullscreen: true,
            store: {
                type: 'personnel',
            },
            columns: [
                { text: 'Name', dataIndex: 'name', sortable: true, flex: 1 },
                { text: 'Email', dataIndex: 'email', sortable: true, flex: 1 },
                { text: 'Phone', dataIndex: 'phone', sortable: true, flex: 1 }
            ],
            bbar: {
                store: {
                    type: 'personnel',
                },
                xtype: 'pagingtoolbar',
                displayInfo: true
            },
            // columns: [
            //     { text: 'Name', dataIndex: 'name', flex: 1 },
            //     { text: 'Email', dataIndex: 'email', flex: 1 },
            //     { text: 'Phone', dataIndex: 'phone', flex: 1 }
            // ],

            listeners: {
                select: 'onItemSelected',
            },
        });

商店:Personnel.js

Ext.define('CRUD.store.Personnel', {
        extend: 'Ext.data.Store',

        alias: 'store.personnel',

        model: 'CRUD.model.User',

        id: 'list',

        fields: [
            'name', 'email', 'phone'
        ],

        // data: [
        //     { name: 'Jean Luc', email: "jeanluc.picard@enterprise.com", phone: "555-111-1111" },
        //     { name: 'Worf', email: "worf.moghsson@enterprise.com", phone: "555-222-2222" },
        //     { name: 'Deanna', email: "deanna.troi@enterprise.com", phone: "555-333-3333" },
        //     { name: 'Data', email: "mr.data@enterprise.com", phone: "555-444-4444" }
        // ],
        autoLoad: {
            start: 0,
            limit: itemsPerPage
        },
        buffered: true,
        pageSize: itemsPerPage,
        remoteSort: true,
        proxy: {
            type: 'jsonp', //cross domain calls - json parser
            url: 'http://localhost:8080/list',
            enablePaging: true,
            reader: {
                type: 'json',
                totalProperty: 'total'
            },

        },
        // proxy: {
        //     type: 'memory',
        //     reader: {
        //         type: 'json',
        //     }
        // },

});

【问题讨论】:

    标签: extjs sencha-architect


    【解决方案1】:

    bbar: { 商店:{ 类型:'人员', }, xtype: '分页工具栏', 显示信息:真 },

    我已经删除了 bbar 内的存储,它可以工作。感谢您的合作。

    【讨论】:

    • 你拯救了我的一天
    【解决方案2】:

    你使用 store 的方式,ExtJS 会在你每次更改页面时做一个请求,将页码参数发送到设置为 store 的 URL。

    如果您想使用 ExtJS 进行客户端分页,您必须将商店的代理类型设置为 memory,将您的数据加载到商店中,然后 ExtJS Grid 将按照您的预期处理分页。

    像这样发送Ext.Ajax.Request

    Ext.Ajax.request({
        url: 'http://localhost:8080/list',
        success: function(response) {
            dataStore.setProxy({
                type: "memory",
                enablePaging: true,
                data: Ext.JSON.decode(response.responseText) //here you need to adapt to your response structure
            });
            dataStore.load();
        }
    });
    

    【讨论】:

    • 感谢您的回复。实际上,存在跨域问题。所以我正在使用JsonP。 Ajax 不适用于跨域请求。
    【解决方案3】:

    对于跨域,您可以调用Ext.data.JsonP.request()方法并处理响应,如下代码所示:

    Ext.data.JsonP.request({
            url: 'data1.json',
            success: function (response) {
                var myData = [];
                Ext.Array.forEach(response.data, function (item) {
                    myData.push({
                        name: item.name,
                        email: item.email,
                        phone: item.phone
                    });
                });
                store.setProxy({
                    type: "memory",
                    enablePaging: true,
                    data: myData
                });
                store.load();
            }
        });
    

    查看此fiddle 以获取完整的工作示例。

    【讨论】:

    • 对我来说,成功在代理内部或外部都不起作用,我已经给出了警报或 console.log 但没有进入 Success 函数。您正在使用 Ext.data.JsonP.request,请告诉我如何使用代理编写。
    • 我使用 Ext.data.JsonP.request() 因为您的要求是进行客户端分页。为此,示例小提琴首先获取完整的数据集,然后使用内存代理进行分页。如果您想在每次单击下一个按钮时从跨域发送部分数据,那么这个fiddle 可以做到。它使用 jsonp 代理并且工作完美,但分页不起作用,因为没有服务器端代码来处理请求中的分页信息。 (后端代码发送完整的数据集。)
    • JsonP 仅适用于 GET 方法,因此请验证您的代码。如果您有 Post 方法,则后端必须正确发送 Access-Control-Allow-Origin: * 标头。参考here
    • 如果您只想进行本地分页,请参考post
    猜你喜欢
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多