【问题标题】:ExtJS4 Grid store/model showing empty row(s)ExtJS4 网格存储/模型显示空行
【发布时间】:2013-09-05 20:34:29
【问题描述】:

我的问题和这个问题很相似:

ExtJS4 gridPanel data not showing

但在语法和行为方面略有不同,我花了几天时间通过多种方式尝试解决但失败了。

请注意:我必须通过调用父构造函数而不是json字段构造来保持SharpKit.NET的生成行为,如下面的代码

Ext.define("Core.Scripts.model.Book", {
    extend: "Ext.data.Model",
    fields: ["title", "pages"] // Do not use this
});

Ext.define("Core.Scripts.model.Book", {
    extend: "Ext.data.Model",
    constructor: function () {
        this.callParent([{ fields: ["title", "pages"] }]); // Use this
    }
});

这是我在 jsfiddle http://jsfiddle.net/thanhptr/LqXan/ 上的简化版本的链接。 Bellow 是我复制的代码,此代码仍然无法修复:

Ext.define("Core.Scripts.model.Book", {
    extend: "Ext.data.Model",
    constructor: function () {
        this.callParent([{ fields: ["title", "pages"] }]);
    }
});
Ext.define("Core.Scripts.store.Store", {
    extend: "Ext.data.Store",
    constructor: function () {
        this.callParent([{
            model: "Core.Scripts.model.Book",
            data: [
                { title: "book 1", pages: 10 },
                { title: "book 2", pages: 20 }
            ]
        }]);
    }
});
Ext.define("Core.Scripts.view.GridPanel", {
    extend: "Ext.grid.Panel",
    constructor: function () {
        this.callParent([{
            store: new Core.Scripts.store.Store(),
            region: "center",
            columns: [
                { header: "title", dataIndex: "title" },
                { header: "pages", dataIndex: "pages" }
            ]
        }]);
    }
});
Ext.define("Core.Scripts.view.DetailViewport", {
    extend: "Ext.container.Viewport",
    constructor: function () {
        this.callParent([{
            frame: true,
            layout: "border",
            items: [new Core.Scripts.view.GridPanel()]
        }]);
    }
});
Ext.onReady(function () {
    var viewPort = new Core.Scripts.view.DetailViewport();
});

【问题讨论】:

    标签: javascript extjs model store gridpanel


    【解决方案1】:

    我也无法让您的示例运行,但我更改了一些代码并让它运行。

    Ext.define("Core.Scripts.model.Book", {
        extend: "Ext.data.Model",
        fields: ["title", "pages"]
    });
    Ext.define("Core.Scripts.store.Store", {
        extend: "Ext.data.Store",
        model: "Core.Scripts.model.Book",
        data: [
            { title: "book 1", pages: 10 },
            { title: "book 2", pages: 20 }
        ]
    });
    
    Ext.define("Core.Scripts.view.GridPanel", {
        extend: "Ext.grid.Panel",
        region: "center",
        height: '200',
        store: Ext.create('Core.Scripts.store.Store'),
        columns: [
            { header: "title", dataIndex: "title" },
            { header: "pages", dataIndex: "pages" }
        ]
    
    });
    
    Ext.define("Core.Scripts.view.DetailViewport", {
        extend: "Ext.container.Viewport",
        frame: true,
        layout: "border",
        initComponent: function () {
            this.items = [new Core.Scripts.view.GridPanel];
            this.callParent(arguments);     
        }
    
    });
    Ext.onReady(function () {
        var viewPort = new Core.Scripts.view.DetailViewport();
    });
    

    【讨论】:

    • 感谢 philosofis 的帮助!但我想将代码的语法和格式保留为 SharpKit 生成代码,在我上面发布的代码中,SharpKit 生成需要调用基本构造函数(而不是声明为您的修改)。
    猜你喜欢
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 2015-03-30
    相关资源
    最近更新 更多