【问题标题】:ExtJS Grid Not Displaying Rest DataExtJS 网格不显示剩余数据
【发布时间】:2018-10-16 08:20:23
【问题描述】:

我创建了一个迷你 EXTJS 应用程序,定义了模型、商店和网格。我已验证商店正在运行,因为我可以使用 Chrome 调试工具创建实例并查看数据。但是,当我尝试在网格中显示数据时,它永远不会显示。

这里是 app.js 的代码:

Ext.application({
launch: function () {
    Ext.define('Companies', {
        extend: 'Ext.data.Model',
        fields: ['id', 'link', 'name']
    });

    Ext.define('CompaniesStore', {
        extend: 'Ext.data.Store',
        model: 'Companies',
        storeId: 'cStore',
        autoLoad: true,
        proxy: {
            type: 'rest',
            url: 'http://corky52547.somee.com/Service1.svc/Companies'
        }
    });

    Ext.create('Ext.container.Viewport', {
        name : "viewPort2",
        layout: 'fit',
        renderTo: Ext.getBody(),
        items: [
            {
                title: 'Bill Reminder Web'
            },
            {
                xtype: 'grid',
                title: 'Bills',
                height: 100,
                width: 100,
                columns: [
                    {text: 'ID', width: 100, dataIndex: 'id'},
                    {text: 'Link', flex: 1, dataIndex: 'link'},
                    {text: 'Name', width: 200, dataIndex: 'name'}
                ],
                store: Ext.create('CompaniesStore',{})
            }
        ]
    });
}
});

更新:

我现在可以显示要显示的数据,但像这样没有主题。如何更新主题?

【问题讨论】:

    标签: extjs store


    【解决方案1】:

    CORS(跨域请求)正在阻止对域的请求。 Layout Fit 也会导致一些问题。

    要让 CORS 正常工作,您需要添加

    访问控制允许来源:*

    否则,您可以使用中间件代理,如cors-anywhere

    字段名称等小错误应与它们在响应中可用的确切大小写匹配。

    这是一个有效的 POC 代码:

    Ext.application({
        name: "Application",
        launch: function () {
            Ext.define('Companies', {
                extend: 'Ext.data.Model',
                fields: ['ID', 'Link', 'Name']
            });
    
            Ext.define('CompaniesStore', {
                extend: 'Ext.data.Store',
                model: 'Companies',
                storeId: 'cStore',
                autoLoad: true,
                proxy: {
                    type: 'rest',
                    url: 'https://cors-anywhere.herokuapp.com/http://corky52547.somee.com/Service1.svc/Companies'
                }
            });
    
            Ext.create('Ext.container.Viewport', {
                name: "viewPort2",
                renderTo: Ext.getBody(),
                items: [{
                    title: 'Bill Reminder Web'
                }, {
                    xtype: 'grid',
                    title: 'Bills',
                    flex: 1,
                    columns: [{
                        text: 'ID',
                        width: 100,
                        dataIndex: 'ID'
                    }, {
                        text: 'Link',
                        flex: 1,
                        dataIndex: 'Link'
                    }, {
                        text: 'Name',
                        width: 200,
                        dataIndex: 'Name'
                    }],
                    store: Ext.create('CompaniesStore', {})
                }]
            });
        }
    });
    

    这是工作小提琴: https://fiddle.sencha.com/#view/editor&fiddle/2gbc

    【讨论】:

    • 我确认这在本地工作,但我还有其他后续问题。当我在小提琴中查看它时,它附有很好的主题,我的没有主题。我上传到原来的问题。如何获取更新的主题?
    • 如果您使用 sencha cmd 创建了应用程序,那么您可以编辑 app.json 并使用定义的主题更改其中的主题 (docs.sencha.com/extjs/6.0.2/guides/core_concepts/theming.html)。如果您在盒子外使用它,您应该可以通过导入主题 css 来应用它们。在我的情况下,使用 sencha fiddle,它通过在 index.html 中包含 cdn.sencha.com/ext/commercial/6.0.1/build/classic/theme-crisp/… 来应用 css
    猜你喜欢
    • 1970-01-01
    • 2014-09-06
    • 2013-08-26
    • 1970-01-01
    • 2012-12-28
    • 2017-01-12
    • 2013-12-22
    • 2011-09-01
    • 2013-07-25
    相关资源
    最近更新 更多