[英]How Do I Reference A Control or a Control's Store in ExtJS?
I have a combo box that I need to get access to the store in code so that I can apply a filter to it.我有一个组合框,我需要在代码中访问商店,以便我可以对其应用过滤器。 Here is the definition of the combo.这是组合的定义。
//ItemGeneralPanel.js
Ext.define('myCompany.view.item.ItemGeneralPanel', {
extend: 'Ext.panel.Panel',
alias: 'widget.myApp.ItemGeneralPanel',
layout: 'vbox',
bodyPadding: 4,
defaults: { width: 800 },
items: [
{
xtype: 'combobox',
fieldLabel: 'Replenishment Source',
displayField: 'name',
valueField: 'id',
queryMode: 'local',
forceSelection: true,
bind: { value: '{item.sourceId}', store: '{replenishmentSourceList}' }
},
]
});
My ItemController has this in it:我的 ItemController 里面有这个:
//ItemController.js
stores: [
'item.ItemList',
'item.ReplenishmentSourceList'
],
And my store looks like this:我的商店看起来像这样:
//ReplenishmentSourceList.js
Ext.define('myCompany.store.item.ReplenishmentSourceList', {
extend: 'Ext.data.Store',
model: 'myCompany.model.Source',
sorters: 'name'
});
And the model just has a list of fields(Source.js):而 model 只有一个字段列表(Source.js):
How do I reference this combo box in my controller so that I can get a reference to its store and then apply a filter to the results coming back.如何在我的 controller 中引用此组合框,以便获得对其存储的引用,然后对返回的结果应用过滤器。 Something like this:像这样的东西:
//ItemEditViewController.js
myFunction: function (facilId) {
this.lookup('replenishmentSourceList').getStore().load({
scope: this,
callback: function (records, operation, success) {
if (!success) {
Ext.log({ level: 'error', msg: 'Error loading facility list', dump: operation });
var text = (operation.getError() ? operation.getError().response.responseText : operation.getResponse().responseText);
var msg = Ext.decode(text).message;
Ext.Msg.show({ title: 'Error', msg: 'Error loading Source data.<br>' + msg, buttons: Ext.Msg.OK, icon: Ext.Msg.ERROR });
}
else {
this.lookup('replenishmentSourceList').getStore().setFilters({
property: 'facilityId',
operator: '==',
value: 'facilId'
});
This isn't working, so I figured if I could get the combobox, I could do something like: myRefToComboBox.getStore()....这不起作用,所以我想如果我能得到 combobox,我可以做类似的事情:myRefToComboBox.getStore()....
Any ideas?有任何想法吗?
If you want to get the store directly then you can simply use storeId
and perform a lookup on created stores Ext.data.StoreManager.lookup('myStore')
which will return the store instance.如果您想直接获取商店,那么您可以简单地使用storeId
并在创建的商店Ext.data.StoreManager.lookup('myStore')
上执行查找,这将返回商店实例。 Refer docs for Ext.data.StoreManager
.请参阅Ext.data.StoreManager
的文档。
Below is a sample which you can try out in fiddle (Check console as it prints the store instance using store manager):以下是您可以在小提琴中试用的示例(检查控制台,因为它使用商店管理器打印商店实例):
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.define('myCompany.store.item.ReplenishmentSourceList', {
alias: 'store.replenishmentSourceList',
extend: 'Ext.data.Store',
sorters: 'name'
});
Ext.define('myCompany.view.item.ItemGeneralPanel', {
extend: 'Ext.panel.Panel',
alias: 'widget.myApp.ItemGeneralPanel',
layout: 'vbox',
bodyPadding: 4,
defaults: {
width: 800
},
items: [{
xtype: 'combobox',
fieldLabel: 'Replenishment Source',
displayField: 'name',
valueField: 'id',
queryMode: 'local',
forceSelection: true,
store: {
type: 'replenishmentSourceList',
storeId: 'myStore'
}
}, ]
});
Ext.create({
xtype: 'myApp.ItemGeneralPanel',
renderTo: Ext.getBody()
});
console.log(Ext.data.StoreManager.lookup('myStore'));
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.