[英]How to get the value of selected displayField in ExtJS Combobox
How to get the value of selected displayField in ExtJS 3.4 ComboBox? 如何在ExtJS 3.4 ComboBox中获取所选displayField的值? getValue() returns valueField, but I need other. getValue()返回valueField,但我需要其他的。
combo.getValue() -> the valueField combo.getValue() - > valueField
combo.getRawValue() -> the displayField combo.getRawValue() - > displayField
If this is the case, 如果是这种情况,
displayField : 'countryName',
valueField : 'countryId',
then following function gives the required displayFiled (Even more than 1 fields are there in store you can get them too) 然后跟随函数给出所需的displayFiled(存储中甚至超过1个字段,你也可以得到它们)
function getFieldValues(combo, nameIn, nameOut){
try{
var r = combo.getStore().find(nameIn,combo.getValue());
return combo.getStore().getAt(r).get(nameOut);
}
catch(err){
return'error';
}
}
Way to get the displayfield or any other filed which is in store : 获取显示字段或存储中的任何其他字段的方式:
var item = getFieldValues(Ext.getCmp('combo'), 'countryId', 'countryName');
Maybe u just user store.filter(), right? 也许你只是用户store.filter(),对吧? If that, try clear filter and load again like below: 如果是这样,尝试清除过滤器并再次加载,如下所示:
onProvinceSelected: function (com,record,index)
{
var provinceCode = com.getValue();
var postGrid = this.lookupReference('postgrid');
if (provinceCode != 0) {
postGrid.store.filter('ProvinceCode', provinceCode);
} else {
postGrid.store.filters.clear();
postGrid.getStore().load();
}
}
I'm using the lastSelectionText property of the ComboBox; 我正在使用ComboBox的lastSelectionText属性; works fine for me, but it is an undocumented feature and thus may break at any time... 对我来说很好,但它是一个没有文档的功能,因此可能随时中断...
Ext.override(Ext.form.ComboBox,
{
getDisplayValue: function () {
return this.lastSelectionText;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.