将数据从json文件加载到extjs中 [英] Loading data from a json file into extjs
问题描述
我有一个.json文件,其内容应该由Ext.data.Store读取并由Ext.grid.Panel显示(extjs 4).但是,不显示任何数据,仅显示网格.代码是:
I have a .json file whose content is supposed to be read by Ext.data.Store and displayed by Ext.grid.Panel (extjs 4). However, no data is displayed, only the grid is. The code is:
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文件加载脚本时出错.能否请你帮忙?谢谢!
Inline data gets displayed but when i am trying to read from a json file, it does not work. I am using firefox and firebug says that there is an error loading the script from my .js file. Could you please help? Thanks!
推荐答案
非常感谢大家.现在工作正常.服务器找不到文件,因为路径不正确.经过一番试验后,我终于能够通过提供正确的路径从json文件中获取json数据,例如-"TestPortlet3-portlet/js/example.json".最初,我只提供"/example.json"或"users.json".将.json文件保存在正确的文件夹中并提供正确的路径后,我能够显示json数据:)
Thanks a lot everyone. It is working fine now. The server could not find the files because the path was not proper. After experimenting a bit, I was finally able to fetch the json data from the json file by giving a proper path, like - "TestPortlet3-portlet/js/example.json". Initially, I was only giving "/example.json" or "users.json". On keeping the .json file in the correct folder and giving the correct path, I was able to display the json data :)
这篇关于将数据从json文件加载到extjs中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!