首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将getTotalCount()值从JSON添加到变量

将getTotalCount()值从JSON添加到变量
EN

Stack Overflow用户
提问于 2012-05-04 04:26:37
回答 1查看 807关注 0票数 0

此程序应检查getTotalCount()的值是否大于一个数字(对于example10),如果大于,则显示警告窗口。

我的问题是如何将getTotalCount()的值赋给变量。

代码语言:javascript
复制
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是:

代码语言:javascript
复制
{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"}]}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-04 05:19:08

将样本末尾替换为:

代码语言:javascript
复制
Store.on('load', function() {

  var total_num = Store.getTotalCount();

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

}, this, { single: true });
Store.load();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10438833

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档