2012-05-03 42 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

你需要寫一個onload事件處理程序。你的處理程序(函數)將在商店加載時被調用,並且在這個函數中,你執行你的檢查並顯示警告/無論什麼。 –

回答

1

替換與樣品的結束:

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

    var total_num = Store.getTotalCount(); 

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

}, this, { single: true }); 
Store.load();