Store filter in sencha touch

China☆狼群 提交于 2019-12-10 13:57:30

问题


I have store having structure :

Ext.create('Ext.data.Store', {
    fields: [
        'title'
    ],
    data: [{
        title: 'ABC'
    }, {
        title: 'ABC2'
    }, {
        title: 'ABC3'
    }, {
        title: 'ABC4'
    }, {
        title: 'ABC5'
    }, {
        title: 'ABC6'
    }]
});

So when I load this store List get populated with all 6 records.

I just wanted to Filter this store on button click I just wanted to get some selected record out of this 6 record Can It be possible.

Provide me Some Idea or Working code.


回答1:


To filter the store based on title

Ext.getStore('storeId').filter("title", "ABC3");

To clear filter

 Ext.getStore('storeId').clearFilter();

See store filter doc

Update

Ext.getStore('storeId').filterBy(function(record){
   var title = record.get('title');
   if(title == "ABC" || title == "ABC1" || title == "ABC2")
      return record;
});



回答2:


My approach is to set a filter on the store when I tap on the button. In my case it was a selectfield and on the change event I filter compared to the current value in the selectfield

    onChangeStatusSelectfield: function (newValue, oldValue) {
    var store = Ext.getStore('CustomVacationRequest');
    console.log('Accepted Filter');
    newValue = this.getStatusSelectfield().getValue();
    console.log(store, newValue);
    store.clearFilter();
    if (store != null);
    store.filter(function (record) {
        if (newValue == record.data.status) { //your data from the store compared to 
                                              //the value from the selectfield
            return true; 
        }
        Ext.getCmp("VacationRequestsManagerList").refresh() //refresh your list   
});

},

This is just my part of the controller. Handle events and buttons and stores at your own choice&need. Good luck!



来源:https://stackoverflow.com/questions/18606212/store-filter-in-sencha-touch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!