2012-05-03 3 views
0

このプログラムは、getTotalCount()の値が数値(たとえば10)より大きいかどうかをチェックし、警告ウィンドウがあれば表示します。JSONから変数へのgetTotalCount()値の追加

私の問題は、変数にgetTotalCount()の値を割り当てる方法です。

var Store = new Ext.data.Store({ 
     id: 'ID_Store', 
     proxy: new Ext.data.HttpProxy({ 
       url: 'get.php',  
       method: 'POST' 
      }), 
     baseParams:{task: "LIST"}, 
     reader: new Ext.data.JsonReader({ 
        root: 'results', 
        totalProperty: 'total', 
        id: 'id' 
       },[ 
        {name: 'IDclass', type: 'int', mapping: 'id_class'}, 
        {name: 'Class', type: 'string', mapping: 'class'} 
       ]) 
    }); 


Store.load; 
var total_num = Store.getTotalCount(); 

if(total_num > 10){ 
    alert("greater than 10"); 
} 

JSONは次のとおりです。

{success:true}{total:23,results:[{"id_class":"1","class":"V-1"},{"id_class":"2","class":"V-2"},{"id_class":"3","class":"V-3"},{"id_class":"4","class":"V-4"},{"id_class":"5","class":"V-5"},{"id_class":"6","class":"VI-1"},{"id_class":"7","class":"VI-2"},{"id_class":"8","class":"VI-3"},{"id_class":"9","class":"VI-4"},{"id_class":"10","class":"VI-5"},{"id_class":"11","class":"VII-1"},{"id_class":"12","class":"VII-2"},{"id_class":"13","class":"VII-3"},{"id_class":"14","class":"VII-4"},{"id_class":"15","class":"VII-5"},{"id_class":"16","class":"VIII-1"},{"id_class":"17","class":"VIII-2"},{"id_class":"18","class":"VIII-3"},{"id_class":"19","class":"VIII-4"},{"id_class":"20","class":"VIII-5"}]} 
+1

。ストアがロードされるたびにハンドラ(関数)が呼び出され、この関数では、あなたはチェックを行い、警告を表示します。 –

答えて

1

はあなたのサンプルの終わりを置き換えて:あなたはのonloadイベントハンドラを記述する必要が

Store.on('load', function() { 

    var total_num = Store.getTotalCount(); 

    if(total_num > 10){ 
    alert("greater than 10"); 
    } 

}, this, { single: true }); 
Store.load(); 
関連する問題