简体   繁体   中英

Sencha Touch 2 Filter a List Store

I have the following code as my main javascript file for displaying a list + buttons. It all shows properly and everything like adding items to the store works great, but is there a simple way to get the list to only display values where the name equals a certain value?

Ext.define("MyProject.view.Main", {
extend: 'Ext.NavigationView',
requires: ['Ext.NavigationView', 'Ext.dataview.List'],
xtype: 'myproject-main',

config: {
items: [
{
  title: 'List of Data',
  layout: 'fit',
  xtype: 'container',
  itemId: 'listContainer',
  items: [
  {
    xtype: 'list',
    store: 'DataStuff',
    itemTpl: '{name}',
    emptyText: 'No data added yet'
  },
  {
    xtype: 'container',
    docked: 'bottom',
    padding: '5px',
    layout: 'hbox',
    items: [{ xtype: 'button', itemId: 'addBtn', text: 'Add Data', ui: 'confirm', width: '50%', align: 'left' }, { xtype: 'button', itemId: 'updateBtn', text: 'Update Data', ui: 'action', width: '50%', align: 'right' }]
  }
  ]
}
]
}
});

I had thought there was a simple filters: category I could add under the store but couldn't find anything that worked.

List displays items that provided by store. For controls list filter you should control his store fitlers. Example

var store = list.getStore();
store.filter('category', 'first');
//or
var customFilter = function(record){
     return soAnyCheckForRecods(record);
}
store.filterBy(customFilter);

More information about filters look here http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Store

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM