0

サーバーから JSON を取得したいのですが、django サーバー ビュー関数は次のとおりです。

def showChart(request):
    data = [{"id":1, "name":"Tom", "email":"a@a.com"}, {"id":2, "name":"Bosh", "email":"c@c.com"}]
    return HttpResponse(json.dumps(data), mimetype="application/json");

明らかに、showChart() は json を返します。

私のフロントエンドextjs4コード:

Ext.onReady(function() {
Ext.define('ProductionInfo', {
    extend: 'Ext.data.Model',
    fields: ['email', 'id', 'name']
});

var store_new = Ext.create('Ext.data.Store', {
    model: 'ProductionInfo',
    proxy: {
      type: 'ajax',
      url : 'http://localhost:8000/production_data',
      reader: {
          type: 'json'
      }
    }
});

store_new.load();
alert(store_new.getCount());

});

ただし、警告ダイアログには「0」が表示されますが、正しい答えは「2」です。では、なぜサーバーから JSON を取得できないのでしょうか? (Chorme と Firefox で GET リクエストを使用して適切な JSON を取得できます)

4

1 に答える 1

0

私のサンプルを確認できます: https://github.com/lucassus/extjs4-account-manager これは Rails アプリケーションですが、json メカニズムは非常に似ています。

基本的に、有効なモデルを定義する必要がありますproxy: https://github.com/lucassus/extjs4-account-manager/blob/master/app/assets/javascripts/app/model/User.jsと属性
を持つストアmodel: https://github.com/lucassus/extjs4-account-manager/blob/master/app/assets/javascripts/app/store/Users.js

于 2012-04-25T08:38:44.497 に答える