0

我想使用 sencha touch 解析 xml,我已经尝试了 stckovrflow 中的所有可能性,但没有任何显示:

XML 数据:来自:http ://www.aufaitmaroc.com/feeds/maroc.xml

商店:

 Ext.define("MyApp2.store.NewsStore", {
 extend: "Ext.data.Store",
 requires: ["Ext.data.proxy.JsonP", "Ext.dataview.List", "MyApp2.model.News"           ,"Ext.data.reader.Xml"],
config: {
model: "MyApp2.model.News",
autoLoad: true,
proxy: {
    type: 'jsonp',
    url: 'http://www.aufaitmaroc.com/feeds/maroc.xml',
    reader: {
        type: 'xml',
        record: 'item',
        rootProperty: 'channel'
        }
    }
}    
});

我的模型:

Ext.define("MyApp2.model.News", {
extend: "Ext.data.Model",
config: {
type:'tree',
fields: [
{name: 'title', type: 'auto'}

 ]
  } 
   });

我的观点 :

 {
                    xtype: "list",
                    store: "NewsStore",
                    itemTpl: '<h1>{title}</h1>'
 }

我在 chrome 的控制台中有这个错误:

图片来自我的浏览器

我试图解决我的问题:我在我的 apache 的 HTTPD.conf 中添加了这个(我正在使用 WampServer)

    AddType application/x-font-woff .woff
    AddType application/rss+xml .xml

我创建了:httpd-proxy.conf 并将其放在额外的文件夹中

我的 httpd-proxy.conf

 ProxyRequests Off
 ProxyPreserveHost On

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyPass /EMBackend http://localhost:8383/MyApp2/index.html
ProxyPassReverse /EMBackend http://localhost:8383/MyApp2/index.html
<Location /EMBackend>
    Order allow,deny
    Allow from all
 </Location>

我已将此添加到 httpd.conf:

 Include conf/extra/httpd-proxy.conf

& 仍然无法显示任何数据。任何帮助将不胜感激:)

Ps:我尝试像这样使用JsonP:

       proxy: {
    type: 'jsonp',
     url: 'https://ajax.googleapis.com/ajax/services/feed/load?         v=1.0&q=http://www.aufaitmaroc.com/feeds/maroc.xml',
    reader: {
        type: 'json',
        rootProperty: 'responseData.feed.entries'
        }
    }

我没有得到所有数据,你可以尝试将 url 放入浏览器。

4

1 回答 1

2

AFAIK JSONP 不适用于 xml。您将需要使用 yql 之类的服务将 xml 转换为 json。 这个小提琴是这样做的演示

Ext.define('MyApp.model.Station', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
            'title'
        ]
    }
});

Ext.define('MyApp.store.Stations', {
    extend: 'Ext.data.Store',
    requires: 'MyApp.model.Station',
    config: {
        autoLoad: true,
        model: 'MyApp.model.Station',
        proxy: {
            type: 'jsonp',
            //url    : 'http://www.aufaitmaroc.com/feeds/maroc.xml',
            url: 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%20%3D%20%22http%3A%2F%2Fnews.google.co.in%2Fnews%3Fpz%3D1%26cf%3Dall%26ned%3Din%26hl%3Den%26output%3Drss%22&format=json&diagnostics=true',
            reader: {
                type: 'json',
                rootProperty: 'query.results.item'
            }
        }
    }
});

Ext.define('MyApp.list.List', {
    extend: 'Ext.List',
    config: {
        fullscreen: true,
        itemTpl: '{title}',
        store: Ext.create('MyApp.store.Stations')
    }
});

Ext.create('MyApp.list.List');

使用 YQL,转到 yql 控制台页面 - http://developer.yahoo.com/yql/console/

在 YQL 语句框中键入以下行。'从 rss 中选择 *,其中 url = " http://www.aufaitmaroc.com/feeds/maroc.xml "'

在下面的单选按钮中选择 json 选项

清除单选按钮侧面的输入框。它应该是空的。

取消选中“诊断”和“调试”复选框。

然后按“测试”按钮。这应该会给你下面的输出。

现在,在这一切之后,转到页面底部。应该有“其余查询”部分。有一个网址。请注意,在 url 的末尾会有类似 '&callback=' 的内容。删除它,并将剩余的用作商店的 url。url 的回调部分由 sencha 自动处理。

于 2013-05-26T14:20:42.123 回答