0

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

ExtJS4 gridPanel 数据未显示

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

请注意:我必须通过调用父构造函数而不是 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();
});
4

1 回答 1

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();
});
于 2013-09-02T18:31:49.317 回答