【问题标题】:RSS Feed as a list using XMLStore in Sencha Touch 2在 Sencha Touch 2 中使用 XMLStore 作为列表的 RSS Feed
【发布时间】:2012-12-17 22:20:51
【问题描述】:

我正在尝试将提要显示为列表。当我尝试使用读取器类型为 json 执行此操作时,它工作正常。但是,使用类型为 xml 时,它不起作用。我得到一个例外:

资源被解释为脚本,但使用 MIME 类型 text/xml 传输:“http://feeds.feedburner.com/TechCrunch/?_dc=1345109660600&page=1&start=0&limit=25&callback=Ext.data.JsonP.callback1 ".* *Uncaught SyntaxError: Unexpected token

Ext.define('TestViews.view.RSSFeedView', {
    requires:[
        'TestViews.view.CommonTitleBar',
        'TestViews.view.CommonContainer',
        'TestViews.locale.MsgResource'
    ],
    extend: 'Ext.Panel',
    xtype: 'Test-rssfeedview',
    id:'rssFeedView',
    config: {
        fullscreen: true,
        layout: {
            type: 'vbox'
        },
        autoDestroy: true,
        items: [
            {
                xtype: 'Test-commontitlebar',
                title: 'RSS Feed Component'
            },
            {
                xtype: 'list',
                id: 'rssFeedList',
                title : 'RSS Feed View',

                                    itemId:"testList",
                                    onItemDisclosure: true,
                                    itemTpl: '{title}',
                flex: 1,
               store:{
                   model: "TestViews.model.RSSFeedViewModel",
                   autoLoad: true,
                   implicitIncludes: true,
                   proxy: {
                       type: 'jsonp',
                        url: 'http://feeds.feedburner.com/TechCrunch/',                          
                       reader: {
                           type: 'xml',
                           root: 'channel',
                            record: 'channel'
                           }
                       }
               },
                width: '100%',                    
                autoDestroy: true,
            }
        ]
    }
})

型号:

enter Ext.define('TestViews.model.RSSFeedViewModel', {
extend: 'Ext.data.Model',

config: {
    fields: [
        'title','description'
    ]
}});

你能告诉我我在这里做错了什么吗?

【问题讨论】:

  • 您使用代理类型 jsonp,因此它必须期望 json 作为响应,这就是您收到错误的原因。即使您想使用 xml,然后尝试阅读器类型 ajax。
  • 感谢纳雷什的回复。但是,代理类型可以是:Ajax - 根据我的说法,将请求发送到同一域上的服务器或 JsonP - 将请求发送到不同域上的服务器。那么,这里还有什么问题吗?

标签: sencha-touch-2


【解决方案1】:

我认为您不能将 XML 读取为 JSONP。看看 JSONP 是如何工作的:

同源策略可防止任何浏览器从不同的 URL 加载数据。要解决此问题,您可以在 DOM 中添加一个 -Tag,其中 src 属性包含您要加载的数据的 URL。

但是在那之后,您在这个新脚本标签的开始和结束之间有了数据(在您的例子中是 RSS 提要数据)。浏览器开始将其解释为 JavaScript 并且 - 砰! 意外的令牌 ...没错,因为它不是 JavaScript,而是 RSS。

总结:JSONP 只能用于从另一个 URL 加载 JavaScript!

解决方案: 您可以将 RSS 数据包装为 JSON 中的字符串。 Google API 在这里为您提供帮助:

http://ajax.googleapis.com/ajax/services/feed/load?q=URL&v=1.0&num=10&output=json-in-script

这将为您提供一个 JSON 对象,其中包含转换后的提要数据。在 API Docs 中搜索参数,对您有帮助。

致谢:http://www.alaafu.com/rssreader-sencha/#favorites/first

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-17
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多