Goran
Goran

Reputation: 17

Adding getTotalCount() value from JSON to the variable

This program should check whether the value of getTotalCount() is greater thana a number (for example10) and display the alert window if it is.

My problem is how to assign a value of getTotalCount() to a variable.

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 is:

{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"}]}

Upvotes: 0

Views: 815

Answers (1)

sha
sha

Reputation: 17860

Replace end of your sample with:

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

  var total_num = Store.getTotalCount();

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

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

Upvotes: 1

Related Questions