如何更改 Dojo TabContainer 行为以仅打开外部链接而不是显示 ContentPane?

发布于 2024-12-04 18:32:16 字数 1366 浏览 2 评论 0原文

我正在使用具有多个不同的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女七分熟 2024-12-11 18:32:16

ContentPanes 实际上并不是 iframe,因此设置 window.location.href 会更改整个页面(dojo 应用程序)的 url,而不仅仅是 ContentPane。你有没有尝试过这样的事情:

cp2.set('href', 'http://www.google.com/')

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:

cp2.set('href', 'http://www.google.com/')
℡Ms空城旧梦 2024-12-11 18:32:16

满足上述要求的一个可能的解决方法是重写 ContentPanecontrolButtononClick 事件:

/*
 * ...
 */

var cp2 = new dijit.layout.ContentPane({
    title: 'Test 2',
    style: 'padding: 10px;'
});

/*
 * ...
 */

tc_nav.addChild(cp2);

/*
 * ...
 */

tc_nav.startup();

/*
 * ...
 */

cp2.controlButton.onClick = function() {
    window.location.href = 'http://www.google.com/';
};

请注意不要附加其他函数到 onClick 事件(例如通过 dojo.connect(cp2.controlButton, 'onClick', function() { /* ... */ });),但是而不是覆盖它,否则ContentPane 的内容将首先被调用。

请进一步注意,必须首先调用 TabContainerstartup() 函数才能使 controlButton 对象可访问。

A possible workaround to meet the above mentioned requirements is to override the onClick event of the ContentPane's controlButton:

/*
 * ...
 */

var cp2 = new dijit.layout.ContentPane({
    title: 'Test 2',
    style: 'padding: 10px;'
});

/*
 * ...
 */

tc_nav.addChild(cp2);

/*
 * ...
 */

tc_nav.startup();

/*
 * ...
 */

cp2.controlButton.onClick = function() {
    window.location.href = 'http://www.google.com/';
};

Please note not to attach another function to the onClick event (e. g. by dojo.connect(cp2.controlButton, 'onClick', function() { /* ... */ });), but rather to override it, otherwise the ContentPane's content would be called up first.

Please note further the TabContainer's startup() function has to be invoked first to make the controlButton object accessible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文