将数据从 JSON 文件导入到 Store
我已经开始开发一个应用程序,我使用 Sencha Touch 进行前端设计和 java 查询后端的数据库。但是,我无法将两者结合在一起。我尝试将来自 java 查询的数据以 json 格式返回到 .json 文件中,然后通过商店将其加载到我的应用程序中,但它似乎不起作用。我在 Chrome 控制台中收到错误,如下所示。
选项 localhost:8080/ProficyAppData/WebContent/app/store/info.json?_dc=1342618907990&page=1&start=0&limit=25 资源加载失败
我的项目包含在一个 Eclipse Java Web 项目中,这样我就可以轻松地使用 localhost 服务器。我不确定为什么 json 数据没有加载到商店中。
店铺:
Ext.define('MyApp.store.Questions', {
extend: 'Ext.data.Store',
config: {
autoLoad: true,
model: 'MyApp.model.Question',
proxy: {
type: 'ajax',
url: 'localhost:8080/ProficyAppData/WebContent/app/store/info.json',
reader: 'json'
},
listeners: {
load: function() {
console.log(this);
}
},
}
});
模型:
Ext.define('MyApp.model.Question', {
extend: 'Ext.data.Model',
config: {
fields: ['id', 'criteria', 'description', 'questionName', 'type']
}
});
信息.json:
[
{
"id": 1,
"criteria": "no criteria yet",
"description": "no description yet",
"questionName": "no question yet",
"type": "n/a"
},
{
"id": 2,
"criteria": "no criteria yet",
"description": "no description yet",
"questionName": "no question yet",
"type": "n/a"
},
{
"id": 3,
"criteria": "no criteria yet",
"description": "no description yet",
"questionName": "no question yet",
"type": "n/a"
},
{
"id": 4,
"criteria": "no criteria yet",
"description": "no description yet",
"questionName": "no question yet",
"type": "n/a"
},
{
"id": 5,
"criteria": "no criteria yet",
"description": "no description yet",
"questionName": "no question yet",
"type": "n/a"
},
{
"id": 6,
"criteria": "no criteria yet",
"description": "no description yet",
"questionName": "no question yet",
"type": "n/a"
}
]
[1]: http://i.stack.imgur.com/3zxuD.png