Dijit TabContainer Events - onFocus

旧城冷巷雨未停 提交于 2019-12-21 20:37:26

问题


I have a Tab Container and I want to execute some js when I click on a tab's title bar.

I can't seem to figure out how to add an event to that.


EDIT:

It looks like I'll be using onFocus, but I'm still having trouble finding the proper syntax.


EDIT: Found onFocus and onBlur, but still having trouble getting it to work.


回答1:


You need to connect to the _transition event.

var tabs = dijit.byId("tabs");
dojo.connect(tabs,"_transition", function(newPage, oldPage){
    console.log("I was showing: ", oldPage || "nothing");
    console.log("I am now showing: ", newPage);
});

Where "tabs" is your TabContainer.




回答2:


Here's a complete code sample that works in Dojo 1.8, I've tested it:

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 
            alert(panel.selectedChildWidget.id);  
        });
    });
});



回答3:


The correct Dojo 1.7+ should be;

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

another way could be

var tabs = registry.byId('someTabs');
aspect.after(tabs, "selectChild", function (event) {
     console.log("You selected ", tabs.selectedChildWidget.id);
});


来源:https://stackoverflow.com/questions/7262740/dijit-tabcontainer-events-onfocus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!