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

drnojrws  于 2022-12-08  发布在  Dojo
关注(0)|答案(4)|浏览(179)

DOJO TabContainer是否有在更改选项卡时触发的事件?
英译汉我想它会的,但是我在文档中找不到任何关于它的东西。
SOLVED:看起来我在这里找到了一个解决方案:
Dijit TabContainer Events - onFocus
不是最可搜索的主题标题:/

3b6akqbq

3b6akqbq1#

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/

vs3odd8k

vs3odd8k2#

docs;

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

9vw9lbht3#

除了@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

mwngjboj

mwngjboj4#

这是一个在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);
    });
});

相关问题