0

该程序应检查 getTotalCount() 的值是否大于一个数字(例如 10),如果是则显示警报窗口。

我的问题是如何将 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"}]}
4

1 回答 1

1

将样品的末尾替换为:

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

  var total_num = Store.getTotalCount();

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

}, this, { single: true });
Store.load();
于 2012-05-03T21:19:07.907 回答