看看 ExtJS。它具有对象“存储”,它能够存储结构化数据并允许对其进行操作,例如排序、过滤、查询。例如,您的任务可以这样解决:
Ext.application({
name: 'HelloExt',
launch: function() {
Ext.create('Ext.data.Store', {
storeId:'UsersStore',
model: 'User',
fields: [ 'id', 'name', 'title', 'filter1', 'filter2', 'filter3' ],
data: [
{ name: 'Ed', title: 'CEO', filter1: true, filter2: false, filter3: true },
{ name: 'Tommy', title: 'CTO', filter1: false, filter2: false, filter3: false },
{ name: 'Aaron', title: 'COO', filter1: true, filter2: true, filter3: true },
{ name: 'Jamie', title: 'CFO', filter1: true, filter2: true, filter3: false }
]
});
function filterStore() {
var store = Ext.data.StoreManager.lookup('UsersStore');
store.clearFilter();
store.filter([
{ property: 'filter1', value: Ext.getCmp('Filter1CB').getValue() },
{ property: 'filter2', value: Ext.getCmp('Filter2CB').getValue() },
{ property: 'filter3', value: Ext.getCmp('Filter3CB').getValue() }
]);
}
Ext.create('Ext.container.Viewport', {
layout: 'vbox',
layoutConfig: {
vbox: {
align: 'stretch'
}
},
items: [
{
xtype: 'panel',
border: false,
padding: 10,
items: {
flex: 1,
xtype: 'fieldcontainer',
items: [
{ fieldLabel: 'Filter1', xtype: 'checkbox', id: 'Filter1CB', handler: filterStore },
{ fieldLabel: 'Filter2', xtype: 'checkbox', id: 'Filter2CB', handler: filterStore },
{ fieldLabel: 'Filter3', xtype: 'checkbox', id: 'Filter3CB', handler: filterStore }
]
}
},
{
flex: 1,
xtype: 'gridpanel',
title: 'Users',
store: Ext.data.StoreManager.lookup('UsersStore'),
columns: [
{ header: 'Name', dataIndex: 'name' },
{ header: 'Title', dataIndex: 'title' }
]
}
]
});
}
});
小提琴:http: //jsfiddle.net/Q55ym/1/