日期:2014-05-16 浏览次数:20558 次
在Extjs设计界面,很多时候并不需要将所有的数据都显示到界面上,这样子我们可以通过在创建store时添加filter属性或调用filterBy方法实现。
1、设计时设置filter属性
//数据模型Model
Ext.define('model.AppProject', {
    extend:'Ext.data.Model',
    fields:[
         {name:'indexIdApp',mapping:'application>indexId'},
       {name:'orgNameApp', mapping:'application>orgName'},
       {name:'verifyResultApp', mapping:'application>verifyResultApp',type:'int'}
    ]
});
//创建store
var proAppStore = Ext.create('Ext.data.Store', {
    model: 'model.AppProject',
    autoLoad:true,
    filterOnLoad:true,
    proxy:{
        type: 'ajax',
        method:'post',
        extraParams:{headValue:RetrieveAppProject,bodyValue:"indexId:*^^",handleMsg:AppRetrieveMsg},
        url : 'HTPApp.CSP.ServiceProxy.cls',
        reader:{
        type:'xml',
        record:'EvaluateOrg',
        totalRecords:'@total'
        }
      },
     filters: [
        {//添加过滤掉未审核和审核未通过的申请
            property: 'verifyResultApp',
            value   : /^\+?[1-9]*$/
        }
    ]
    
});
以上代码中在创建的时候设置filters时,限定model中verifyResultApp为正整数,其中用到正则表达式,值得注意的是,我们需要在store中添加filterOnLoad:true,这样在加载的时候这个过滤就会有效果。
2、在需要过滤的时候调用filterBy方法
proAppStore.filterBy(function(record) { 
                      return record.get('orgNameApp') == "IT";   
                  });
如上代码我们就可以得到'orgNameApp'为IT的数据
当然多个条件限制时可以在return的时候用&&连接
 return record.get('verifyResultApp') == 0&&record.get('orgNameApp') == orgNameQuik