extJS网格错误,未显示JSON数据

was*_*lli 5 javascript json extjs

我把我的商店配置为:

var store = new Ext.data.JsonStore({
url: 'gridData.php',
root: 'movies',
fields: ['film_id', 'title', 'release_year', 'rating']
});
Run Code Online (Sandbox Code Playgroud)

然后将我的网格定义为:

var grid = new Ext.grid.GridPanel({
    title:'Movies',
    store: store,
    columns: [
                { header: "ID", width: 30, dataIndex: 'film_id',sortable: true, hidden:true },
                { id: 'title-col', header: "Title", width: 180,dataIndex: 'title', sortable: true },
                { header: "Rating", width: 75, dataIndex: 'rating',sortable: true },
                { header: "Year", width: 75, dataIndex: 'release_year',sortable: true, align: 'center' }
        ],
    autoExpandColumn: 'title-col',
    renderTo: Ext.getBody(),
    width: 600,
    height: 300,
    loadMask: true
});
Run Code Online (Sandbox Code Playgroud)

然后我加载商店:

store.load();
Run Code Online (Sandbox Code Playgroud)

我正在用Ext.onReady方法做这一切.我要显示的数据是从php文件中获取的,该文件格式如下:

{ "count":2, "movies":[{ "film_id":"1", "title":"ACADEMY DINOSAUR", "description":"An Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies", "release_year":"2006", "rating":"PG", "special_features":"Deleted Scenes,Behind the Scenes" }, { "film_id":"2", "title":"ACE GOLDFINGER", "description":"An Astounding Epistle of a Database Administrator And an Explorer who must Find a Car in Ancient China", "release_year":"2006", "rating":"G", "special_features":"Trailers,Deleted Scenes" } ] }
Run Code Online (Sandbox Code Playgroud)

加载页面时,网格会一直显示加载掩码,并且数据永远不会显示.另外,我收到错误a is undefined.我错过了什么?

编辑

我发现在将URL分配给商店但仍然无法解决时存在一些路径问题.我的"gridData.php"文件,JS文件和显示网格的HTML文件位于同一个文件夹中,我在"localhost/myapp"上.请帮忙!

Ask*_*ken 0

假设您正在运行 ExtJS 4,如下定义您的商店:

var store = new Ext.data.JsonStore({
    proxy: {
        url: 'gridData.php',
        type: 'ajax',
        reader: {
            type: 'json',
            root: 'movies'
        }
    },
    fields: ['film_id', 'title', 'release_year', 'rating']
});
Run Code Online (Sandbox Code Playgroud)