问题描述
我在使用 ext js 时遇到问题,我想使用我商店中的引用从我的字段中获取值,但是当我 console.log
时出现错误 lookupReference is not a function
。
我的表格
items: [
{
xtype: 'comboBox',name: 'REC_TERMINAL_CODE_2',fieldLabel: 'Terminal 2',emptyText : 'Terminal',reference: 'terminal2'
},{
xtype: 'comboBox',name: 'REC_TERMINAL_CODE',fieldLabel: 'Terminal',store: {
type: 'terminal'
},displayField: 'terminal_name',valueField: 'terminal_code',value: 'T01',minChars: 3,queryParam: 'q',queryMode: 'remote',editable: false,allowBlank: false,fieldStyle: 'text-transform:uppercase',afterLabelTextTpl: [
'<span style="color:red;font-weight:bold" data-qtip="required"> *</span>'
],flex: 1
},]
在我的终端存储文件中
listeners: {
load: function (store,records,success) {
console.log(this.lookupReference('terminal2'))
if (!success) {
Ext.Msg.confirm('Status Error','This connection Failed,reload ?',function (choice) {
if (choice === 'yes') {
window.location.reload();
}
}
);
}
}
}
解决方法
存储不是组件,因此您可以使用 getReferenceHolder()。您可以使用通用的 Ext.ComponentQuery.query('combobox[reference=terminal2]')[0]
这将返回适合查询的组件数组。
,首先,您的监听器中的 this
不是指诸如组合框等组件。它可能指的是商店实例或控制器类。尝试确保您访问组件实例。可以通过登录到控制台来确定,ExtJs 中的默认组件具有 xtype 属性,例如组合框、容器等。一旦您可以访问该组件(父组件),您就可以通过使用函数找到它的具有命名引用的子组件。
第二,基于他们的docs,您可以使用parentComponent.getReferences()['PARTICULAR_REFERENCE_NAME']
函数通过它的引用获取组件。 parentComponent 可以是表单、容器等。我不知道您使用的是哪个版本的 ExtJS,getReferences
函数可能在较低版本中不存在。
如果你想获取上面例子中的 ExtJS 组件。
然后您已将 referenceHolder
属性启用为 true。
例如参考此链接:
Fetching ExtJs Component in View
此属性启用视图作为组件的引用持有者
更多详情
请参考sench docs链接:
Sencha docs ReferenceHolder