[英]ExtJS4 Transform Combobox onchange() event doesn't work
我在extjs4中有一個轉換ComboBox
:
<script>
Ext.onReady(function() {
Ext.tip.QuickTipManager.init();
var transformed = Ext.create('Ext.form.field.ComboBox', {
typeAhead: true,
transform: 'DisplayListID',
forceSelection: true
});
});
</script>
<select id="DisplayListID" onChange="change();">
<option> ...
</select>
ExtJS成功將我的HTML select
轉換為ComboBox
但是當我選擇一個元素時,不會觸發onChange
事件。
如何將javascript函數change()
綁定到我的轉換CombBox
?
通過向組合框添加偵聽器來使用ExtJs change事件:
listeners: {
change: change
}
第二個變化是您的功能。
Lorenz是正確的,您應該使用change listener ,但是,如果您嘗試同時轉換多個組合 ,並且這些組合已經定義了功能,則需要手動將每個新的轉換后的組合及其處理程序方法鏈接起來,這可能是真實的惡夢。 但是,您可以繼承ComboBox控件的子類,並使其自動處理方法鏈接 ,為此,您必須考慮到在初始化ComboBox控件后,原始的“ select”已被刪除。 因此,在調用父ComboBox的init方法之前,必須確保保留對目標方法的引用,否則將無法獲得它,例如:
initComponent: function() {
var me = this,
transform = me.transform,
transformSelect,
transformMethod;
// Check if transform id has been supplied
if(transform) {
// Attempt to retrieve target select from the DOM
transformSelect = Ext.getDom(transform);
// Get sure select node exists
if (transformSelect) {
// Keep a reference to target method
transformMethod = transformSelect.onchange;
}
}
// Now that we have the method info
// Allow ComboBox init method to replace original
// select tag with ExtJs Control
me.callParent(arguments);
// Bind change event with original handler method
me.on('change', transformMethod, me);
}
我在這里創建了一個完整的工作示例 。 希望對你有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.