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

私の知る限り、JSONP は xml では機能しません。xml を json に変換するには、yql などのサービスを使用する必要があります。 このフィドルはそれを行うデモです

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 ステートメント] ボックスに次の行を入力します。'select * from rss where url = " http://www.aufaitmaroc.com/feeds/maroc.xml "'

下のラジオボタンでjsonオプションを選択します

ラジオ ボタンの横にある入力ボックスをクリアします。空である必要があります。

「診断」チェックボックスと「デバッグ」チェックボックスの両方をオフにします。

次に、「テスト」ボタンを押します。これにより、以下の出力が得られます。

このすべての後、ページの下部に移動します。「THE REST QUERY」セクションがあるはずです。URLあります。URL の最後に「&callback=」のようなものがあることに注意してください。これを削除し、残りをストアの URL として使用します。URL のコールバック部分は、sencha によって自動的に処理されます。

于 2013-05-26T14:20:42.123 に答える