Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何捕获dojo TabContainer的子/嵌套(子)选项卡的“id”?_Javascript_Dojo_Dijit.layout - Fatal编程技术网

Javascript 如何捕获dojo TabContainer的子/嵌套(子)选项卡的“id”?

Javascript 如何捕获dojo TabContainer的子/嵌套(子)选项卡的“id”?,javascript,dojo,dijit.layout,Javascript,Dojo,Dijit.layout,我有一组带有子选项卡的选项卡。我需要在单击每个选项卡时获取其id。我首先发现watch函数内置在dojoTabContainer对象中: myTabContainer.watch("selectedChildWidget", function(name, oval, nval){ console.log("selected child changed from ", oval, " to ", nval); }); 这适用于父选项卡,但不适用于子/嵌套子选项卡。我唯一的线索是子选项卡是

我有一组带有子选项卡的选项卡。我需要在单击每个选项卡时获取其
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

我已经找到了答案。我尝试了几种不同的方法,但只有这一种适用于子选项卡。以下是我的解决方案:

使用:

"dijit/registry",
"dojo/on",
在我的dojo
require
语句中

myGridxID
TabContainer
id,它位于我的HTML页面的DIV中,在这里我的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