将数据从json文件加载到extjs

将数据从json文件加载到extjs,json,extjs4,Json,Extjs4,我有一个.json文件,其内容应该由Ext.data.Store读取,并由Ext.grid.Panel(extjs4)显示。但是,不显示任何数据,只显示网格。代码是: var user = Ext.create('Ext.data.Store', { storeId: 'user', model: 'User', autoLoad: 'true', proxy: { type: 'ajax', url : '/users.json'

我有一个.json文件,其内容应该由Ext.data.Store读取,并由Ext.grid.Panel(extjs4)显示。但是,不显示任何数据,只显示网格。代码是:

var user = Ext.create('Ext.data.Store', {
    storeId: 'user',
    model: 'User',
    autoLoad: 'true',
    proxy: {
        type: 'ajax',
        url : '/users.json',
        reader: {type: 'json', root: 'blah'}
    }
});

 Ext.create('Ext.grid.Panel',{
    store :user,
    id : 'user',
    title: 'Users',
    columns : [ 
        {header: 'ID',     dataIndex : 'id'}, 
        {header : 'NAME',  dataIndex : 'name'}, 
        {header : 'Email', dataIndex: 'email'}
    ],
    height :300,
    width: 400,
    renderTo:'my-portlet2'
});
我的json文件是:

{ blah[
  {
    "id": 1,
    "name": "Ed Spencer",
    "email": "ed@sencha.com"
  },
  {
    "id": 2,
    "name": "Abe Elias",
    "email": "abe@sencha.com"
  }
]}
内联数据会显示出来,但当我试图从json文件中读取时,它不起作用。我正在使用firefox,firebug说从我的.js文件加载脚本时出错。你能帮忙吗?谢谢

试试这个:

{ "blah": [
  {
    "id": 1,
    "name": "Ed Spencer",
    "email": "ed@sencha.com"
  },
  {
    "id": 2,
    "name": "Abe Elias",
    "email": "abe@sencha.com"
  }
]}

谢谢大家。它现在运转良好。服务器找不到文件,因为路径不正确。经过一点实验,我终于能够通过给出一个合适的路径从json文件中获取json数据,如“testportlet3portlet/js/example.json”。起初,我只给出“/example.json”或“users.json”。将.json文件保存在正确的文件夹中并给出正确的路径后,我能够显示json数据:)

错误说明了什么?如果复制了GET请求试图执行的URL并将其粘贴到浏览器中,是否可以加载该文件?您提供的json无效。你确定你的users.json文件中有有效的json吗?我做了更正,但仍然不起作用。错误表示找不到资源(404)。可能是什么错误?我试图指定绝对路径,但没有效果。为了获得更多信息,我将这个extjs应用程序作为使用tomcat的liferay MVC portlet运行。我试着将文件保存在webapps目录中,并尽可能地保存在我能想到的任何地方。我每次也做了相应的改变。什么都想不到:(firebug抱怨找不到“ext all debug.js”和“ext all.js”(404)。另外,“ext”没有定义。我在extjs文件夹中有2个js文件,并且在脚本中给出了相同的路径。它还说“yui:未加载:延迟任务”我不知道我哪里出错了……建议plz?如果我诚实,你的问题与这个问题的主题完全不同。我会重新提出一个新问题。无论如何,你知道吗ext脚本的r路径可能在index.html(或类似的东西)中被破坏,如果您提交index.html文件会有所帮助;此外,如果您转到extjs下的examples文件夹,您能找到任何示例项目吗?