4

DOJO TabContainer 是否有在更改选项卡时触发的事件?

我想它会,但我在文档中找不到任何关于它的信息。:(

已解决:看起来我在这里找到了解决方案:

Dijit TabContainer 事件 - onFocus

不是最容易搜索的主题标题:/

4

4 回答 4

7

连接aspect.after到 TabContainer 的selectChild方法:

var tabContainer1 = registry.byId("tabContainer1");

aspect.after(tabContainer1, "selectChild", function() {
    console.log("tab changed");        
});

或者,如果您对特定选项卡感兴趣,请连接到其 ContentPane 的_onShow

var contentPane1 = registry.byId("contentPane1");

aspect.after(contentPane1, "_onShow", function() {
    console.log("[first] tab selected");        
});

在 jsFiddle 上查看它的实际效果:http: //jsfiddle.net/phusick/Mdh4w/

于 2012-05-11T10:04:48.957 回答
7

来自文档

var tabs = registry.byId('someTabs');
tabs.watch("selectedChildWidget", function(name, oval, nval){
    console.log("selected child changed from ", oval, " to ", nval);
});
于 2013-06-06T06:14:45.653 回答
3

除了@phusick 的正确答案之外,所有StackContainers,包括TabContainer您可以订阅的主题的发布。

http://dojotoolkit.org/reference-guide/1.7/dijit/layout/StackContainer.html#published-topics

[widgetId]-addChild,
[widgetId]-removeChild
[widgetId]-selectChild

http://dojotoolkit.org/reference-guide/1.7/dojo/subscribe.html#dojo-subscribe

于 2012-05-11T10:14:44.643 回答
0

这是一个在 Dojo 1.8 中工作的完整代码示例,我已经对其进行了测试。这不是仅在更改选项卡时触发的事件,我无法在 API 中触发它们的任何事件,但至少它适用于 Click 事件。

require(["dijit/registry",  "dojo/on", "dojo/ready", "dojo/domReady!"], function (registry, on, ready) {
    ready(function () { //wait till dom is parsed into dijits
        var panel = registry.byId('mainTab');   //get dijit from its source dom element
        on(panel, "Click", function (event) {   //for some reason onClick event doesn't work 
            $('.hidden_field_id').val(panel.selectedChildWidget.id);  //on click, save the selected child to a hidden field somewhere. this $ is jquery, just change it to 'dojo.query()'
        });
    });
});

//include this function if you want to reselect the tab on page load after a postback
require(["dijit/registry", "dojo/ready", "dojo/domReady!"], function (registry, ready) {
    ready(function () {
        var tabId = $('.hidden_field_id').val();
        if (tabId == null || tabId == "")
            return;
        var panel = registry.byId('mainTab');
        var tab = registry.byId(tabId);
        panel.selectChild(tab);
    });
});
于 2013-02-21T07:35:23.407 回答