如果关闭,我只想打开链接myDiv1
一次(一次点击)除外:
1)如果我点击myDiv1
- >打开一个新标签(“Dashboard 1”) - >它的工作原理
2)如果我点击onClose
中的myDiv1
- >关闭标签(“仪表板1”) - >它的工作原理
3)如果新标签页(“信息显示板1”)已打开,我再次点击myDiv1
我只想选择标签,而不是创建新标签。
我该怎么做第三步???
来自巴黎的亲吻
<script>
require(["dojo/dom-attr", "dojo/query", "dijit/layout/TabContainer", "dijit/layout/ContentPane", "dojo/on", "dojo/dom", "dojo/dom-style", "dojo/mouse", "dojo/dom-construct"],
function(attr, query, TabContainer, ContentPane, on, dom, domStyle, mouse, domConstruct)
{
on(myDiv1, "click", function(evt)
{
var cp1 = new ContentPane(
{
title: myDiv1.innerText,
closable: true,
onClose: function()
{
tc.removeChild(cp1);
},
content: domConstruct.create("iframe",
{
"src": "http://www.bing.com/"
})
});
tc.addChild(cp1, 0);
tc.selectChild(cp1);
});
var tc = new TabContainer(
{
style: "height: 100%; width: 100%;"
}, "tab-window");
tc.startup();
});
</script>
</head>
<body class="claro">
<div style="float:left; width:10%; height:100%">
<div id="myDiv1" data-dojo-type="dijit/MenuItem" style="padding:5px; color:blue; font-size:125%;">Dashboard 1</div>
</div>
<div id="idonglet" style="float:left; width:90%; height:500px">
<div id="tab-window">
<!--<iframe id="myIframe" style="float:left; width:100%; height:100%"></iframe>-->
<div id="output"></div>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
获取TabContainer
的子项并迭代它们并检查其中任何一个的标题是否等于myDiv1.innerText
。如果是,则选择该孩子。
我在此处发布了您的代码中所需的更改。
require(["dojo/dom-attr", "dojo/query", "dijit/layout/TabContainer", "dijit/layout/ContentPane", "dojo/on", "dojo/dom", "dojo/dom-style", "dojo/mouse", "dojo/dom-construct", "dijit/registry"],
function(attr, query, TabContainer, ContentPane, on, dom, domStyle, mouse, domConstruct, registry)
{
on(myDiv1, "click", function(evt)
{
var found= false;
var children= tc.getChildren();
for(var i=0; i<children.length; i+++){
var child= children[i];
if(child.title== myDiv1.innerText){
tc.selectChild(child);
found= true;
break;
}
}
if(!found){
var cp1 = new ContentPane({
title: myDiv1.innerText,
closable: true,
onClose: function()
{
tc.removeChild(cp1);
},
content: domConstruct.create("iframe",
{
"src": "http://www.bing.com/"
})
});
tc.addChild(cp1, 0);
tc.selectChild(cp1);
}
});
var tc = new TabContainer(
{
style: "height: 100%; width: 100%;"
}, "tab-window");
tc.startup();
});