[英]How to get the value of selected displayField in ExtJS Combobox
如何在ExtJS 3.4 ComboBox中獲取所選displayField的值? getValue()返回valueField,但我需要其他的。
combo.getValue() - > valueField
combo.getRawValue() - > displayField
如果是這種情況,
displayField : 'countryName',
valueField : 'countryId',
然后跟隨函數給出所需的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';
}
}
獲取顯示字段或存儲中的任何其他字段的方式:
var item = getFieldValues(Ext.getCmp('combo'), 'countryId', 'countryName');
也許你只是用戶store.filter(),對吧? 如果是這樣,嘗試清除過濾器並再次加載,如下所示:
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();
}
}
我正在使用ComboBox的lastSelectionText屬性; 對我來說很好,但它是一個沒有文檔的功能,因此可能隨時中斷...
Ext.override(Ext.form.ComboBox,
{
getDisplayValue: function () {
return this.lastSelectionText;
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.