gpt4 book ai didi

ExtJS Controller 在超链接点击时触发

转载 作者:行者123 更新时间:2023-12-04 14:17:57 25 4
gpt4 key购买 nike

我已经尝试让它工作了很长一段时间,但我仍然无法找到解决方案,除了在 View 中的监听器中添加 afterrender。但我希望 Controller 处理它。

有没有人知道我如何解决这个问题?

这是我目前文件中的内容
http://pastie.org/2751446

controller/App.js

Ext.define('HD.controller.App', {
extend: 'Ext.app.Controller'
,views: [
'core.Header',
'core.Navigation',
'core.Content'
]
,init: function() {
this.control({
'navigation a[id=tab1]': {
click: this.newTab
}
})
}
,newTab: function() {
console.log('Tab 1 should be loaded now');
}
});

View /核心/Navigation.js
Ext.define('HD.view.core.Navigation', {
extend: 'Ext.panel.Panel'
,name: 'navigation'
,alias: 'widget.navigation'
,layout: 'accordion'
,region: 'west'
,width: 200

,title: 'Navigation'
,collapsible: true

,items: [
{
title: 'Title 1'
,html: '<a id="tab1" style="cursor:pointer;">Tab 1</a>'
},
{
title: 'Title 2'
,html: 'Second'
}
]
});

最佳答案

您尝试引用超链接的方式 a不会工作。

this.control({
'navigation a[id=tab1]': {
click: this.newTab
}
})

那只会寻找 ExtJS 组件,而不是 DOM 元素。您很可能必须在 afterrender 或类似的地方附加点击。这并不意味着您不能将完成所有工作的方法留在 Controller 中。

编辑:
var controller = this;
controller.control({
'navigation': {
afterrender: function() {
Ext.get('tab1').on('click', function() {
controller.newTab();
});
}
}
})

关于ExtJS Controller 在超链接点击时触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7879402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com