我正在使用Sencha 2.1构建一个移动应用程序。我正在尝试加载一个google电子表格,作为列表的数据源。
我已经公开了谷歌电子表格,你可以在这个链接上找到它:
https://docs.google.com/spreadsheet/pub?key=0AhW0xtL9j2bAdHlwRE1qcE1WdDVLa2dRdDBxNTJBV0E&output=html
然而,我无法让它发挥作用。
下面是我到目前为止掌握的代码:
模型
Ext.define('MyApp.model.InfoList', {
extend: 'Ext.data.Model',
config: {
fields: [
'Title',
'Description',
'Icon'
],
idProperty: '_id'
}
});The Store
Ext.define('MyApp.store.InfoList', {
extend : 'Ext.data.Store',
config : {
model : 'MyApp.model.InfoList',
proxy: {
type: 'jsonp',
url : 'https://spreadsheets.google.com/feeds/list/0AhW0xtL9j2bAdHlwRE1qcE1WdDVLa2dRdDBxNTJBV0E/od6/public/basic?alt=json-in-script',
reader: {
type: 'json',
root: 'feed.entry'
}
}
}
});视图
Ext.define('MyApp.view.home.infolist', {
extend : 'Ext.List',
xtype : 'infoListView',
disableSelection: true,
config : {
title : 'Info List',
itemTpl: [
'<div class="itemInfo">',
'<div class="iconDiv">',
'<img src="{Icon}" class="icon"/>',
'</div>',
'<div class="descriptionDiv">',
'<div class="title">{Title}</div>',
'<div class="description">{Description}</div>',
'</div>',
'<div class="disclosureDiv">',
'<img src="images/infoListDisclosure.png" class="iconImage"/>',
'</div>',
'<div class="clear"></div>',
'</div>',
].join(''),
store : 'InfoList'
}
});列表总是空的。如果我在代理中使用jsonp而不是json,应用程序就会停止运行。
有什么方法可以看出我在警报中从代理那里得到了什么响应?或任何可能出现问题的迹象都会受到赞赏。
PS:我在IBM上构建应用程序,但是我使用sencha作为编码。我不确定这会不会影响到什么
谢谢
发布于 2013-05-15 05:37:01
JSON响应中的属性都是小写的,如'title‘& 'content’,而模型字段名的大写字母为'Title‘& 'Description’。此外,JSON中没有像'Description‘这样的字段,它的'content’和‘’title‘数据也在'$t’属性中。
我建议您在控制台中转储并查看已解析的JSON对象,以了解如何正确地呈现其属性。
还有一件事,而不是使用:
用这个:
获取列作为entry对象的属性。在这种情况下,您可以像这样定义模型:
Ext.define('MyApp.model.InfoList', {
extend: 'Ext.data.Model',
config: {
fields: [
{name : 'id',type : 'string', mapping:'id.$t'},
{name : 'Title',type : 'string', mapping:'gsx$Title.$t'},
{name : 'Description',type : 'string', mapping:'gsx$Description.$t'},
{name : 'Icon',type : 'string', mapping:'gsx$Icon.$t'}
],
idProperty: 'id'
}
});https://stackoverflow.com/questions/16543432
复制相似问题