0

我有一组带有子标签的标签。我需要在id单击每个选项卡时获取它。我首先找到watch了对象中内置的函数dojo TabContainer

myTabContainer.watch("selectedChildWidget", function(name, oval, nval){
    console.log("selected child changed from ", oval, " to ", nval);
});

这适用于父选项卡,但不适用于子/嵌套子选项卡。我唯一的线索是子选项卡是ContentPane对象而不是TabContainer对象。

我也试过这个,它也只适用于父标签:

var tcmainid = tcmain.id;
dojo.connect(dijit.byId(tcmainid), "selectChild", function(page){console.log("Page ID: " + page.id)});

这是我的标签创建代码:

var tcmain = new TabContainer({doLayout: false}, 'htmlDDIVid');

var parentTab1 = new ContentPane({title: "Tab1", content: gridx1});
var parentTab2 = new TabContainer({title: "Tab2", doLayout: false, nested: true});

var parentTab2SubTab1 = new ContentPane({title: "SubTab1", content: sub1Gridx});
var parentTab2SubTab2 = new ContentPane({title: "SubTab2", content: sub2Gridx});

parentTab2.addChild(parentTab2SubTab1);
parentTab2.addChild(parentTab2SubTab2);

tcmain.addChild(parentTab1);
tcmain.addChild(parentTab2);

如何id为我的孩子/嵌套子选项卡获取?

4

1 回答 1

0

我想到了。我尝试了几种不同的方法,但只有这种方法适用于子标签。这是我的解决方案:

使用:

"dijit/registry",
"dojo/on",

在我的道场require声明中。

myGridxIDTabContainer存在于我的 HTML 页面的 DIV 中的 id,其中绘制了我的 TabContainer,其中包含我的所有选项卡和子选项卡,每个叶子选项卡都有一个gridx.

// Pickup the onClick and get the ID of the tab or sub tab being clicked, this is used in the case switch statement for updating the grid accordingly
    var tabContainerPanel = registry.byId('myGridxID');   //get dijit from its source dom element

    on(tabContainerPanel, "Click", function (event) {
        selectedTabString = tabContainerPanel.selectedChildWidget.title;

        if (typeof tabContainerPanel.selectedChildWidget.selectedChildWidget !== 'undefined'){
            // There are no child tabs, parent tab only
            selectedTabString = tabContainerPanel.selectedChildWidget.selectedChildWidget.title;
        }

然后我遇到的问题是,gridx 中当前选项卡的点击被拾取。我用 if 语句绕过了这个:

if (selectedTabString !== prevSelectedTabString){

检查并查看gridx我正在单击的当前是否与我刚刚选择的相同,然后它会忽略点击,或者我应该说在点击选项卡时忽略我拥有的代码。在我的代码中单击选项卡时,我会更新该选项卡 Gridx。

于 2015-05-01T14:05:14.957 回答