2012-05-11 79 views

回答

5

連接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/

+0

啊,我實際上使用道場1.61,但方面直到1.7才引入。儘管我已經找到了使用_transition事件的解決方案。我會在8小時後發佈它。 – Greg

+0

Aspect從一開始就在Dojo中,只需使用'dojo.connect'而不是'aspect.after'。一樣的。 – phusick

+0

啊,dojo.connect的作品。 dojo.require(「dojo.aspect」)直到1.7才被支持。 – Greg

2

除了@ phusick的答案,這是正確的,所有StackContainer S,其中包括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

+0

是的,我只是看着'StackContainer :: selectChild'方法源代碼,很驚訝看到'topic.publish(this.id +「 - selectChild,page)''。 – phusick

0

下面是一個完整的代碼示例,在道場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); 
    }); 
}); 
3

從文檔;

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