gpt4 book ai didi

sencha-touch - Sencha Touch - 如何将不同的过滤器应用于一个商店以供不同用途?

转载 作者:行者123 更新时间:2023-12-04 05:22:17 28 4
gpt4 key购买 nike

只是想知道在 Sencha Touch 中是否有处理该问题的方法。一个商店,应用不同的过滤器后,商店可以用于不同的地方。

例如:

我有一家商店:

Ext.regModel('abc', {
fields: [{name: 'tid', type: 'int'}, {name: 'name', type: 'string'}, {name: 'parent', type: 'int'}]
});

var store = new Ext.data.Store({
model: 'abc',
proxy: {
type: 'ajax',
url : 'read.php',
reader: {
type: 'json',
root: 'items',
fields: ['tid', 'name', 'parent']
}
},
autoLoad: true,
});

在 FormPanel 中,它有两个选择字段:

items: [
{
xtype: 'selectfield',
name : 'One',
label: 'Category',
// store: store, <-- Load the whole store
store: function(){
store.filter('name', 'digital'); <-- Load part of store
},
displayField: 'name',
valueField: 'tid'
},{
xtype: 'selectfield',
name : 'Two',
label: 'subCategory',
// store: store, <-- Load the whole store
store: function(){
store.filter('parent', 1); <-- Load part of store
},
displayField: 'name',
valueField: 'tid'
},{
...}
]

最佳答案

不用担心,您需要商店的两个实例。

为什么不扩展你的商店,让它像这样预先配置:

Ext.regModel('abc', {
fields: [{name: 'tid', type: 'int'}, {name: 'name', type: 'string'}, {name: 'parent', type: 'int'}]});

MyStore = Ext.extend(Ext.data.Store, {
constructor: function(config) {

config = Ext.apply({

model: 'abc',
proxy: {
type: 'ajax',
url : 'read.php',
reader: {
type: 'json',
root: 'items',
fields: ['tid', 'name', 'parent']
}
},
autoLoad: true,
}, config);

MyStore.superclass.constructor.call(this, config);

})

然后您可以使用商店的多个实例并按照您的需要过滤它们:

items: [
{
xtype: 'selectfield',
name : 'One',
label: 'Category',
store: new MyStore(), //1st instance of MyStore
displayField: 'name',
valueField: 'tid',
listeners : {
'render' : function(){
this.store.filter('name', 'digital');
}
}
},{
xtype: 'selectfield',
name : 'Two',
label: 'subCategory',
store: new MyStore(), //2nd instance of MyStore
displayField: 'name',
valueField: 'tid',
listeners : {
'render' : function(){
this.store.filter('parent', 1);;
}
}
},{
...}

]

关于sencha-touch - Sencha Touch - 如何将不同的过滤器应用于一个商店以供不同用途?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7815036/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com