我讓你使用ExtJS6假設你的目標是通過這些參數來篩選結果:
在你的榜樣,你定義的數據前面。考慮到這一點,你應該能夠使用「過濾器」的方法在商店:
// use filter method to filter the data on the front-end
var myStore = Ext.create('Ext.data.Store', {
model: 'User',
data : [
{id: '1', firstName: 'Peter', lastName: 'Venkman'},
{id: '2', firstName: 'Egon', lastName: 'Spengler'},
{id: '3', firstName: 'Ray', lastName: 'Stantz'},
{id: '4', firstName: 'Winston', lastName: 'Zeddemore'}
]
});
myStore.filter('id', '1');
// making use of storeId
Ext.getStore('myStore').filter('id', '1');
如果從服務器(通過一個Ajax請求,例如)請求數據最簡單的方式請求數據使用params爲通過在負載通話將PARAMS:
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'string'},
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'age', type: 'int'},
{name: 'eyeColor', type: 'string'}
]
});
var myStore = Ext.create('Ext.data.Store', {
storeId: 'myStore',
model: 'User',
proxy: {
type: 'ajax',
url: '/users.json',
reader: {
type: 'json',
rootProperty: 'users'
}
},
autoLoad: true
});
// adding params on load
Ext.getStore('myStore').load({
params: {id: '1'}
});
如果你想爲每個負載情況下自動注入參數,你可以在「beforeload」事件創建一個偵聽器,並添加PARAMS:
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'string'},
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'age', type: 'int'},
{name: 'eyeColor', type: 'string'}
]
});
var myStore = Ext.create('Ext.data.Store', {
storeId: 'myStore',
model: 'User',
proxy: {
type: 'ajax',
url: '/users.json',
reader: {
type: 'json',
rootProperty: 'users'
}
},
autoLoad: true,
listeners: {
// add params on every store load by injecting on the beforeload event
beforeload: function(store, operation, eOpts) {
operation.setParams({id: '1'});
}
}
});
// the beforeload event kicks off our code to inject params
Ext.getStore('myStore').load();
真棒ŧ hank克里斯托弗巴達盧科 – user1234
很高興你發現我的答案有幫助! –