如何更改 Dojo TabContainer 行为以仅打开外部链接而不是显示 ContentPane?
我正在使用具有多个不同的 ContentPane
子级的 TabContainer
。它们中的每一个都配备了一个 href
参数来获取选择选项卡时显示的外部 AJAX 内容:
dojo.addOnLoad(function() {
var tc_nav = new dijit.layout.TabContainer({
style: 'width: 98%;',
doLayout: false
}, 'tc_nav');
var cp1 = new dijit.layout.ContentPane({
title: 'Test 1',
href: 'ajax?test1',
style: 'padding: 10px;',
selected: true
});
dojo.connect(cp1, 'onShow', function() {
cp1.refresh();
});
/*
* ...
*/
tc_nav.addChild(cp1);
/*
* ...
*/
tc_nav.startup();
});
现在我想在其他选项卡中集成一个其行为应该不同的选项卡:而不是加载将内容放入 ContentPane
中,该选项卡应遵循同一窗口中的简单链接(例如 Link
),留下包含 js/dojo 应用程序的页面。我还没有找到任何令人满意的解决方案,也没有找到符合此要求的 dojo 小部件。最好的方法是什么?
作为一个令人不愉快的解决方法,我创建了一个覆盖的 onShow 事件,触发 window.location.href = '...';
:
var cp2 = new dijit.layout.ContentPane({
title: 'Test 2',
style: 'padding: 10px;'
});
dojo.connect(cp2, 'onShow', function() {
window.location.href = 'http://www.google.com/';
});
此解决方法的一个令人烦恼的缺点是 <首先加载 code>ContentPane,然后设置 window.location.href
,这会导致非常奇特的延迟重新加载效果,从而导致糟糕的用户体验。我想避免这个中间步骤。
I am working with a TabContainer
having several different ContentPane
children. Each of them is equipped with a href
param to fetch external AJAX content shown when a tab is being selected:
dojo.addOnLoad(function() {
var tc_nav = new dijit.layout.TabContainer({
style: 'width: 98%;',
doLayout: false
}, 'tc_nav');
var cp1 = new dijit.layout.ContentPane({
title: 'Test 1',
href: 'ajax?test1',
style: 'padding: 10px;',
selected: true
});
dojo.connect(cp1, 'onShow', function() {
cp1.refresh();
});
/*
* ...
*/
tc_nav.addChild(cp1);
/*
* ...
*/
tc_nav.startup();
});
Now I want to integrate a tab among the others which should be different in its behaviour: Instead of loading content into a ContentPane
the tab should follow a simple link in the same window (like a <a href="http://www.google.com/">Link</a>
), leaving the page containing the js/dojo app. I didn't find any satisfying solution yet, nor a dojo widget matching this requirement. What would be the best approach?
As an unpleasant workaround I created an overridden onShow
event firing a window.location.href = '...';
:
var cp2 = new dijit.layout.ContentPane({
title: 'Test 2',
style: 'padding: 10px;'
});
dojo.connect(cp2, 'onShow', function() {
window.location.href = 'http://www.google.com/';
});
An annoying disadvantage of this workaround is the fact the ContentPane
is loaded first and afterwards the window.location.href
is set, which leads to a quite peculiar lazy reload effect and consequently to a bad user experience. I would like to avoid this intermediate step.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ContentPanes 实际上并不是 iframe,因此设置 window.location.href 会更改整个页面(dojo 应用程序)的 url,而不仅仅是 ContentPane。你有没有尝试过这样的事情:
ContentPanes are not actually iframes, so setting window.location.href would change the url of your entire page (dojo app) not just the ContentPane. Have you tried something like this:
满足上述要求的一个可能的解决方法是重写
ContentPane
的controlButton
的onClick
事件:请注意不要附加其他函数到
onClick
事件(例如通过dojo.connect(cp2.controlButton, 'onClick', function() { /* ... */ });
),但是而不是覆盖它,否则ContentPane
的内容将首先被调用。请进一步注意,必须首先调用
TabContainer
的startup()
函数才能使controlButton
对象可访问。A possible workaround to meet the above mentioned requirements is to override the
onClick
event of theContentPane
'scontrolButton
:Please note not to attach another function to the
onClick
event (e. g. bydojo.connect(cp2.controlButton, 'onClick', function() { /* ... */ });
), but rather to override it, otherwise theContentPane
's content would be called up first.Please note further the
TabContainer
'sstartup()
function has to be invoked first to make thecontrolButton
object accessible.