dojo TabContainer是否有更改标签时触发的事件?

时间:2012-05-11 09:47:22

标签: javascript dojo

DOJO TabContainer是否有更改标签时触发的事件?

我想它会,但我在文档中找不到任何相关内容。 :(

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

Dijit TabContainer Events - onFocus

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

4 个答案:

答案 0 :(得分: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/

答案 1 :(得分:5)

来自文档;

var tabs = registry.byId('someTabs');
tabs.watch("selectedChildWidget", function(name, oval, nval){
    console.log("selected child changed from ", oval, " to ", nval);
});

答案 2 :(得分:3)

除了@ phusick的答案,这是正确的,所有StackContainer,包括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

答案 3 :(得分: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);
    });
});