我正在尝试将一个Sencha Touch 2前端放在一起,以使用Rails后端(返回JSON)。但是,我发现运行以下脚本根本不会联系服务器。我确信这个问题有一个非常简单的解决方案!如果我将行autoLoad: true
添加到我的商店,然后联系服务器,但我在浏览器中看到一个永无止境的加载图像。
非常感谢您的帮助!如果你想了解更多信息,请知道。
- 贾里德
index.js
ListDemo = new Ext.Application({
name: "ListDemo",
launch: function() {
ListDemo.listPanel = new Ext.List({
id: 'disclosurelist',
store: ListDemo.ListStore,
itemTpl: '<div class="contact">{title}</div>',
onItemDisclosure: function(record, btn, index) {
ListDemo.detailPanel.update(record.data);
ListDemo.Viewport.setActiveItem('detailpanel');
}
});
ListDemo.Viewport = new Ext.Panel ({
fullscreen: true,
layout: 'card',
cardSwitchAnimation: 'slide',
items: [ListDemo.listPanel]
});
}
});
data.js
Ext.regModel('Article', {
fields: [
{name: 'title', type: 'string'},
{name: 'url', type: 'string'}
],
proxy: {
type: 'rest',
url : 'articles',
format: 'json',
reader: {
type: 'json',
root: 'articles',
record: 'entry'
}
}
});
ListDemo.ListStore = new Ext.data.Store({
model: 'Article'
})
如果我访问localhost:3000 / articles.json:
,这是服务器响应的内容{"articles":
[
{"created_at":"2012-07-18T23:54:08Z","from":null,"id":1,"image":"","title":"Inquiry Seeks Accomplices of Bomber in Bulgaria","updated_at":"2012-07-21T06:13:54Z","url":"www.newyorktimes.com"},
{"created_at":"2012-07-19T00:01:35Z","from":null,"id":2,"image":"","title":"Changing Harlem Celebrates Queen of Soul Food","updated_at":"2012-07-21T06:26:13Z","url":"www.newyorktimes.com/harlem"}
]
}
答案 0 :(得分:0)
您的服务器脚本应返回如下所示的JSON:
{
"success": true,
"articles": [
{"created_at":"2012-07-18T23:54:08Z","from":null,"id":1,"image":"","title":"Inquiry Seeks Accomplices of Bomber in Bulgaria","updated_at":"2012-07-21T06:13:54Z","url":"www.newyorktimes.com"},
{"created_at":"2012-07-19T00:01:35Z","from":null,"id":2,"image":"","title":"Changing Harlem Celebrates Queen of Soul Food","updated_at":"2012-07-21T06:26:13Z","url":"www.newyorktimes.com/harlem"}
]
}