【问题标题】:List not populating with a JsonP proxy列表未填充 JsonP 代理
【发布时间】:2012-04-15 04:05:04
【问题描述】:

我想要一个导航视图。我正在尝试使用 JsonP 代理填充 Sencha Touch 中的列表。

这是我迄今为止尝试过的示例代码 sn-p:

var view = Ext.define('MyApp.view.NavigateView', {
    extend: 'Ext.navigation.View',
    xtype:'navigateview',

    config : {
        fullscreen:true,
        styleHtmlContent:true,
        scrollable:true,

        items : [
            {
                title:'Navigation',
                items : [
                    {
                        xtype:'list',
                        store: {
                            fields : ['title','author'],
                            proxy : {
                                type:'jsonp',
                                url:'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog',
                                    reader: {
                                         type: 'json',
                                         rootProperty: 'responseData.feed.entries'
                                    }
                            },
                            autoLoad:true,
                        },
                        itemTpl:'<div class="contact">{title} <strong>{author}</strong></div>',
                        listeners : {
                            itemtap : function(){
                                Ext.Msg.alert('Called');
                                }
                            }
                        }
                ],

            }
        ]   
   }
});

但问题是,我的列表没有被填充。列表中没有显示任何项目。

另外,我经常在控制台上收到此错误。

XMLHttpRequest 无法加载 http://api.tinyhippos.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=list.php%3F_dc%3D1334462633038%26page%3D1%26start%3D0%26limit%3D25。 Access-Control-Allow-Origin 不允许来源http://localhost

有人请指导吗?我在这里缺少什么?

【问题讨论】:

  • 看起来您的错误不在使用 jsonp 的 googleapis 提要中。您在哪里使用 tinyhippos.com,那应该是您的错误位置。
  • 不,我不这么认为。当我提供用于 sencha 触摸图表而不是用于普通 sencha 触摸应用程序的“sencha-touch.css”文件时,我能够看到数据,但没有正确呈现。因此,数据即将到来,但未正确呈现。可能是什么原因?
  • 但是如果你查看错误,它说 XMLHttpRequest 无法从 tinyhippo 加载某些东西,

标签: javascript list proxy extjs sencha-touch-2


【解决方案1】:

在跨域中使用 AJAX 请求时,我遇到了同样的错误。 看看here

您必须确保使用 jsonp 正确配置服务器部分

首先确定当您在浏览器中禁用网络安全时您的应用程序是否能正常运行

找到你的 chrome 安装目录 然后输入你的cmd:chrome --disable-web-security

【讨论】:

    【解决方案2】:

    您的Ext.navigation.View 对象包含一个包含您的列表的Ext.Component 对象(xtype 未定义,因此默认为“组件”)。如果您将列表直接作为视图的一个项目,它将被渲染:

    var view = Ext.define('MyApp.view.NavigateView', {
      extend: 'Ext.navigation.View',
      xtype: 'navigateview',
    
      config : {
        fullscreen: true,
        styleHtmlContent: true,
        scrollable: true,
    
        items : [{
          title: 'Navigation',
          xtype: 'list',
          store: {
            fields: ['title','author'],
            proxy: {
              type: 'jsonp',
              url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog',
              reader: {
                type: 'json',
                rootProperty: 'responseData.feed.entries'
              }
            },
            autoLoad:true
          },
          itemTpl: '<div class="contact">{title} <strong>{author}</strong></div>'
        }]
      }
    });
    

    注意 1:不确定您的代码为什么不起作用。

    注意2:您提到的错误与您的代码sn-p无关

    【讨论】:

      猜你喜欢
      • 2019-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      • 2020-06-11
      • 2014-10-14
      相关资源
      最近更新 更多