首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与Sencha Ext.List

与Sencha Ext.List
EN

Stack Overflow用户
提问于 2013-05-14 12:40:56
回答 1查看 333关注 0票数 0

我正在使用Sencha 2.1构建一个移动应用程序。我正在尝试加载一个google电子表格,作为列表的数据源。

我已经公开了谷歌电子表格,你可以在这个链接上找到它:

https://docs.google.com/spreadsheet/pub?key=0AhW0xtL9j2bAdHlwRE1qcE1WdDVLa2dRdDBxNTJBV0E&output=html

然而,我无法让它发挥作用。

下面是我到目前为止掌握的代码:

模型

代码语言:javascript
复制
Ext.define('MyApp.model.InfoList', {
    extend: 'Ext.data.Model',

    config: {
        fields: [
            'Title',
            'Description',
            'Icon'
        ],
        idProperty: '_id'
    }
});

The Store

代码语言:javascript
复制
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'
        }
    }

}
});

视图

代码语言:javascript
复制
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作为编码。我不确定这会不会影响到什么

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-15 05:37:01

JSON响应中的属性都是小写的,如'title‘& 'content’,而模型字段名的大写字母为'Title‘& 'Description’。此外,JSON中没有像'Description‘这样的字段,它的'content’和‘’title‘数据也在'$t’属性中。

我建议您在控制台中转储并查看已解析的JSON对象,以了解如何正确地呈现其属性。

还有一件事,而不是使用:

https://spreadsheets.google.com/feeds/list/0AhW0xtL9j2bAdHlwRE1qcE1WdDVLa2dRdDBxNTJBV0E/od6/public/basic?alt=json-in-script

用这个:

https://spreadsheets.google.com/feeds/list/0AhW0xtL9j2bAdHlwRE1qcE1WdDVLa2dRdDBxNTJBV0E/od6/public/values?alt=json-in-script

获取列作为entry对象的属性。在这种情况下,您可以像这样定义模型:

代码语言:javascript
复制
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'
    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16543432

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档