ExtJS4网格商店/模型显示空行

时间:2013-09-02 17:25:07

标签: javascript extjs model store gridpanel

我的问题与这个问题非常相似:

  

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/上的简化版本的链接。贝娄是我复制的代码,这段代码仍然没有修复:

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();
});

1 个答案:

答案 0 :(得分:0)

我也无法让你的例子工作,但我改变了一些代码并让它工作。

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();
});