【問題描述】: 有些時候Ext.form.FromPanel中的組件都寫好了,但是初始化的時候需要給組件填寫初始值,例如combobox,textarea等。
【原因分析】: 因爲form最初被實例化的時候,combobox是沒有值的。 此時在reset前,增加一句話,即可保證reset到正確的值: Ext.getCmp('combobox元素的id號').originalValue = value;
在本人的使用過程中還發現另外一個問題,採用上面的方法貌似是解決了初始化爲空值的問題,但是卻發現當點擊其他頁面再返回到該頁面時combobox表單元素標籤名顯示重複,但下拉選擇框不見了,每次彈出該表單窗口頁面combobox表單元素標籤名就多一個顯示出來。 查看API,發現combobox存在多個ID: An itemId can be used as an alternative way to get a reference to a component 抱着嘗試的態度:
最終上面重複問題是解決了,但是卻發現重置失效了。最後註釋掉Ext.Container.getComponent('combobox元素的itemid號').originalValue = value; 行代碼居然啥事都沒了,就一個itemid搞定撒了。
部分代碼如下: //formUI:表單窗口對象(同事自定義的具有表單和窗口特性的) //formpanel:表單面板FormPanel對象 //點擊“新增”按鈕彈出表單窗口界面 |
function add() {
formUI.show("新增");
// Ext.Container.getComponent('combobox_type').originalValue = "fieldtype";
// Ext.getCmp('combobox_type').originalValue = "fieldtype";
formpanel.getForm().reset();
}
//在Grid列表中一行記錄上單擊彈出表單窗口界面,對應記錄中的值設置到表單中
gridUI.on("cellclick",function(di,record,grid, rowIndex, colIndex, e){
formUI.show("編輯");
formpanel.getForm().setValues(record.data);
});
//表單中對應Combobox元素腳本:
{
layout : 'form',
labelWidth : 60,
labelAlign : 'right',
colspan : 2,
items : {
itemid:'combobox_type',
xtype : 'combo', //注意:Extjs版本是3.3
fieldLabel : '擴展類型',
width : 150,
hiddenName : 'extensiontype',
colspan : 2,
store : new Ext.data.SimpleStore({
fields : ['name', 'value'],
data : [["字段類型", "fieldtype"], ["分詞器", "tokenizer"],["Filter過濾器","filter"],["文本處理","textprocess"],["文件解析","fileparser"],["積分策略","similarity"]]
}),
editable : false,
displayField : 'name',
value : 'fieldtype',
valueField : 'value',
typeAhead : true,
mode : 'local',
forceSelection : true,
triggerAction : 'all',
selectOnFocus : true
}
}