我正在尝试为32
字段过滤值为privilege
的JSON。我尝试了多种过滤方式,但是仍然返回所有行而不是过滤后的行。
Ext.onReady(function () {
// create the data store
var store = new Ext.data.Store({
url: url,
reader: new Ext.data.JsonReader({
root: 'keys',
idProperty: 'key',
fields: ['key', 'name']
}),
autoLoad: true
});
store.filter({
property: 'privileges',
value: 32,
type: 'int',
exactMatch: true
});
//create the Grid
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{
id :'name',
header : 'Name',
width : 500,
sortable : true,
dataIndex: 'name'
},
{
header : 'Key',
width : 500,
sortable : false,
dataIndex: 'key'
},
{
header : 'Regenerate',
width : 300,
dataIndex: ''
}
],
stripeRows: true,
height: 350,
title: 'Administrator Keys'
});
grid.render('restApiKeyContent');
});
当前我的JSON如下
{
"id": "abc123",
"name": "Test",
"queue": "test",
"expire": "2118-11-27T02:05:15.546778Z",
"keys": [
{
"key": "64654asdsad1sd1",
"customer": "Test Customer",
"externalUser": "123213",
"name": "Jenna Testing API Key 1",
"privileges": 31
},
{
"key": "7c5362f98f084ae7b76b8484f660fdcf",
"customer": "Test Customer",
"externalUser": "123213",
"name": "Jenna Testing API Key 1",
"privileges": 16
}
}
是否赞赏有人可以指导我如何通过以Keys
为根的特定字段来过滤JSON?
答案 0 :(得分:1)
这可能会对您有所帮助。在加载存储后,在JSONReader中添加privileges
字段并过滤存储:
Ext.onReady(function () {
// create the data store
var store = new Ext.data.Store({
url: 'filter-store-extjs3.json',
reader: new Ext.data.JsonReader({
root: 'keys',
idProperty: 'key',
fields: ['key', 'name', 'privileges']
}),
autoLoad: true,
listeners: {
load: function() {
store.filter('privileges', '16', true, true);
}
}
});
var grid = new Ext.grid.GridPanel({
renderTo: Ext.getBody(),
store: store,
columns: [
{
id :'name',
header : 'Name',
width : 500,
sortable : true,
dataIndex: 'name'
},
{
header : 'Key',
width : 500,
sortable : false,
dataIndex: 'key'
},
{
header : 'Regenerate',
width : 300,
dataIndex: ''
}
],
stripeRows: true,
height: 350,
title: 'Administrator Keys'
});
});