新手刚刚学习ExtJs 建立了一个简单的表格 大家看一下有什么错误呢? 一直都报json语法错误
下面是ext代码:Ext.require(['*']);
var a = document.documentElement.clientWidth;
var b = document.documentElement.clientHeight;
Ext.onReady(function(){
//模型
Ext.define('exec', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'email']
}); //获取数据源
var store = new Ext.data.Store({
model: 'exec',
proxy: {
type: 'ajax',
url : 'exec.json',
reader: {
type: 'json',
model:'exec'
}
},
autoLoad: true
});
//grid panel
Ext.create('Ext.grid.Panel',{
title:'测试表格1',
store: store,
columns:[
{text:'id',dataIndex:'id'},
{text:'name',dataIndex:'name'},
             {text:'email',dataIndex:'email'} ],
width:a,
height:b,
renderTo: Ext.getBody()
});
});exec.json:
[
{"id": 1,"name": "Ed Spencer","email": "[email protected]"},
{"id": 2,"name": "Abe Elias","email": "[email protected]"}
]哪里出错了 求大家给帮忙找找

解决方案 »

  1.   


    var store = new Ext.data.Store({
            model: 'exec',
            proxy: {
                type: 'ajax',
                url : 'exec.json',
                reader: {
                    type: 'json',
                    root:'data'//这里应该是个root吧
                }
            },
            autoLoad: true
        });
        columns:[
                {header:'id',dataIndex:'id'},
                {header:'name',dataIndex:'name'},
                {header:'email',dataIndex:'email'}///应该是header吧        ]
       data:[
    {"id": 1,"name": "Ed Spencer","email": "[email protected]"},
    {"id": 2,"name": "Abe Elias","email": "[email protected]"}
    ]///data在你返回的json数据里
      

  2.   

    直接用data的话 没有任何问题  我想把他写成 json的那种格式var store = new Ext.data.Store({
    model: 'exec',
    data:[
    {"id": 1,"name": "Ed Spencer","email": "[email protected]"},
    {"id": 2,"name": "Abe Elias","email": "[email protected]"}
    ]
    });header 好像和text 效果一样 应该没错
      

  3.   

    [
    {"id": 1,"name": "Ed Spencer","email": "[email protected]"},
    {"id": 2,"name": "Abe Elias","email": "[email protected]"}
    ]
    这个是数组!改成这样:
    {
    "name":"whatever",
    "content":[{"id": 1,"name": "Ed Spencer","email": "[email protected]"},{"id": 2,"name": "Abe Elias","email": "[email protected]"}]
    }
    还有如二楼所说root要选对,这里应该是"content"
      

  4.   


    这样好像也不行  说什么未组织好。 root那边我也改过了 header我也改过了 好是没法读取。 是不能这样读取XX.json 文件吗   我看官方的文档 应该可以这样啊。