2012-02-10 3 views
2

Extjs 4のストアのリスナーのようなものを探していましたが、いくつかの問題に直面しています。Extjsのストアのリスナーを読み込みません。

1) '成功'パラメータは、操作が成功したかどうかを「ロード」リスナメソッドに通知しますが、「成功」パラメータには1つの配列が含まれています。私はその配列に何が含まれているのか知りませんが、 'success.length'プロパティを呼び出した後、私のサーバーサイドコードが応答として送信した実際の行数が含まれていることがわかりました。だから私は '成功'プロパティは実際に私のデータが含まれていると思うが、私はそれについてはわからない。

2)「レコード」または「成功」パラメータでExt.each()メソッドを使用すると、実際のデータが読み込まれません。実際のデータを見るには?ストアの

コードは以下のようになります。

Ext.define('myCompany.store.customerDistribution', { 
    extend: 'Ext.data.TreeStore', 
    autoLoad: true, 

    proxy: { 
     type: 'ajax', 
     url: 'data/customerDistribution/customerCount.json', 
     reader: { 
      type: 'array', 
      root: 'resultset' 
     } 
    }, 
    listeners: { 
     load: function(store, records, success) { 
      /*console.log('store - ' + store + 
         ', typeof(store) - ' + typeof(store) + 
         ', records - ' + records + 
         ', records data - ' + records.data + 
         ', success - ' + success + 
         ', type of success - ' + typeof(success)+ 
         ', success length - ' + success.length); 
      if(records == true) { 
       console.log('records is data property...'); 
      } 
      if(store == true) { 
       console.log('store is a data property...'); 
      } 
      for(r in records) { 
       console.log(r + '\ttypeof(r) -> ' + typeof(r)); 
      } */ 
      if(success && records.length > 0) { 
       var allCountries = []; 
       var previousCountry = undefined; 

       var countryIndex = 0; 
       var stateIndex = 1; 
       var cityIndex = 2; 
       var customerCountIndex = 3; 

       Ext.each(records, function(record, index){ 
        console.log('record - ' + record[0] + ', ' + record[1]); 
       }); 
      } 
     } 
    } 
}); 

私は、ツリーパネルに表示されるように、階層JSONに行ベースのJSONに変換しようとしています。だから私はロード・リスナーを使用しています。

{ 
    "queryInfo":{"totalRows":"100"}, 

    "resultset":[ 
     ["India","India","India",63], 
     ["India",""," Tirupati ",1], 
     ["India",""," UTTARPARA ",1], 
     ["India","Andhra Pradesh",null,61], 
     ["India","Andhra Pradesh"," Chittoor ",1], 
     ["India","Andhra Pradesh"," Guntur ",2], 
     ["India","Andhra Pradesh"," Hyderabad ",58] 
     ], 
    "metadata":[ 
     {"colIndex":0,"colType":"String","colName":"Country"}, 
     {"colIndex":1,"colType":"String","colName":"State"}, 
     {"colIndex":2,"colType":"String","colName":"City"}, 
     {"colIndex":3,"colType":"Integer","colName":"customer_count"} 
    ] 
} 

と私はそれを変換したい::次のように 私のJSONは見え

"resultset": [ 
    countries: [ 
    { 
     name: "India", 
     customer_count: 63 
     states: [ 
      { 
       name: "Andhra Pradesh", 
       customer_count: 61, 
       cities: [ 
        { 
         name: "Tirupati", 
         customer_count: 1 
        }, 
        { 
         name: "UTTARPARA", 
         customer_count: 1 
        }, 
        { 
         name: "Chittoor", 
         customer_count: 1 
        }, 

        { 
         name: "Guntur", 
         customer_count: 2 
        }, 
        { 
         name: "Hydrabad", 
         customer_count: 58 
        } 
       ] 
      } 
     ] 
    } 
] 

助けてください!

答えて

7

誤ったロードイベントの署名が選択されました。 TreeStoreには、それは以下の署名load(Ext.data.TreeStore this, Ext.data.NodeInterface node, Ext.data.Model[] records, Boolean successful, Object eOpts)を持っています。さらに、レコードはツリー構造で配列されているため、eachでレコードを繰り返し処理することはできません。ここで

は、コンソールツリー内の各レコードをログに記録のコード例は次のとおりです。

var store = Ext.create('Ext.data.TreeStore', { 
    model: 'Task', 
    proxy: { 
     type: 'ajax', 
     url: 'treegrid.json' 
    }, 

    logRecord: function(r, depth) { 
     if (!depth) { depth = ''; } 
     console.log(depth + Ext.encode(r.data)); 

     Ext.each(r.childNodes, function(record, index){ 
      this.logRecord(record, depth + ' '); 
     }, this); 
    }, 

    listeners: { 
     load: function(sender, node, records) { 
      Ext.each(records, function(record, index){ 
       this.logRecord(record); 
      }, this); 
     } 
    } 
}); 
+0

素晴らしいです!ありがとう@ロロ – Shekhar

関連する問題