如何在不使用 Addable 插件的情况下在 YUI3 Tabview 小部件中添加新选项卡

发布于 2024-10-14 15:11:33 字数 569 浏览 2 评论 0原文

目前我正在使用 Tabview 可添加插件,由用户单击选项卡视图小部件的添加按钮启动。

现在我还想动态添加一些事件的选项卡。

我尝试使用 Tabview 的添加方法(http://developer.yahoo.com/yui/3/api/WidgetParent.html#method_add)


function myJsFunc(name, content){

tabview3.add({
label: name,
content: '<textarea> </textarea>',
index: Number(tabview3.size())});

}

这里 tabview3 是 Tabview 小部件的全局对象。这似乎不起作用。我有什么遗漏的吗?任何帮助表示赞赏。

Currently I am using Tabview addable plugin, which is initiated by user on clicking add button of tabview widget.

Now I also want to add a tab on some event dynamically.

I tried following using add method (http://developer.yahoo.com/yui/3/api/WidgetParent.html#method_add) of Tabview


function myJsFunc(name, content){

tabview3.add({
label: name,
content: '<textarea> </textarea>',
index: Number(tabview3.size())});

}

Here tabview3 is a global object of Tabview widget. This does not seem to work. Is there any thing which I am missing ? Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

记忆之渊 2024-10-21 15:11:33

以下将允许您创建两个按钮来添加和删除选项卡。

...
<input type="button" id="addTabButton" value="Add Tab" />

<input type="button" id="removeTabButton" value="Remove Tab" />

...
var addTab = function(e) {
    e.preventDefault();
input = {"label":"test","content":"TestContent","index":"2"};
    mainTabView.add(input, input.index);
}

Y.on("click", addTab, ["#addTabButton"]);

var removeTab = function(e) {
    e.preventDefault();
    mainTabView.remove(1);
}

Y.on("click", removeTab, ["#removeTabButton"]);

var mainTabView = new Y.TabView({
srcNode:'#TheMainTabView',
    plugins: [Addable, Removeable]
});
mainTabView.render();
...

Following will allow you to create two buttons to add and remove tabs.

...
<input type="button" id="addTabButton" value="Add Tab" />

<input type="button" id="removeTabButton" value="Remove Tab" />

...
var addTab = function(e) {
    e.preventDefault();
input = {"label":"test","content":"TestContent","index":"2"};
    mainTabView.add(input, input.index);
}

Y.on("click", addTab, ["#addTabButton"]);

var removeTab = function(e) {
    e.preventDefault();
    mainTabView.remove(1);
}

Y.on("click", removeTab, ["#removeTabButton"]);

var mainTabView = new Y.TabView({
srcNode:'#TheMainTabView',
    plugins: [Addable, Removeable]
});
mainTabView.render();
...
烏雲後面有陽光 2024-10-21 15:11:33

我在 YUI3 中也遇到了同样的问题。永远无法弄清楚。如果我可以重新启动该项目,我会选择 YUI2。 YUI2 上有更多文档,更不用说 tabview 仍处于 v3 测试阶段。

话虽这么说,我使用以下代码解决了这个问题:

 var Addable = function(config) {
    Addable.superclass.constructor.apply(this, arguments);
};

Addable.NAME = 'addableTabs';
Addable.NS = 'addable';

Y.extend(Addable, Y.Plugin.Base, {
    ADD_TEMPLATE: '<li class="yui3-tab" title="Add Your Own Custom Tab!">' +
                '<a class="yui3-tab-label yui3-tab-add">+</a></li>',

    initializer: function(config) {
        var tabview = this.get('host');
        tabview.after('render', this.afterRender, this);
        tabview.get('contentBox')
            .delegate('click', this.onAddClick, '.yui3-tab-add', this);
    },

    getTabInput: function() {
        var tabview = this.get('host');
        return {
            label: window.prompt('What do you want to call this tab?:', 'foo'),
            content: window.prompt('Page Url. Replace foo.com with whatever page you want loaded.', '<iframe src="http://www.foo.com" width="100%" height="850px" frameborder="0"></iframe>'),
            index: Number(window.prompt('What tab number would you like this to be (0 = first):', tabview.size()))
        }
    },



    afterRender: function(e) {
        var tabview = this.get('host');
        tabview.get('contentBox').one('> ul').append(this.ADD_TEMPLATE);
    },

    onAddClick: function(e) {
        e.stopPropagation();
        var tabview = this.get('host'),
            input = this.getTabInput();
        tabview.add(input, input.index);
    }
});

I ran into the same problem with YUI3. Never could figure it out. If I could restart the project I would go with YUI2. There is much more documentation on YUI2 not to mention tabview is still in beta for v3.

That being said, I worked around it using the following code:

 var Addable = function(config) {
    Addable.superclass.constructor.apply(this, arguments);
};

Addable.NAME = 'addableTabs';
Addable.NS = 'addable';

Y.extend(Addable, Y.Plugin.Base, {
    ADD_TEMPLATE: '<li class="yui3-tab" title="Add Your Own Custom Tab!">' +
                '<a class="yui3-tab-label yui3-tab-add">+</a></li>',

    initializer: function(config) {
        var tabview = this.get('host');
        tabview.after('render', this.afterRender, this);
        tabview.get('contentBox')
            .delegate('click', this.onAddClick, '.yui3-tab-add', this);
    },

    getTabInput: function() {
        var tabview = this.get('host');
        return {
            label: window.prompt('What do you want to call this tab?:', 'foo'),
            content: window.prompt('Page Url. Replace foo.com with whatever page you want loaded.', '<iframe src="http://www.foo.com" width="100%" height="850px" frameborder="0"></iframe>'),
            index: Number(window.prompt('What tab number would you like this to be (0 = first):', tabview.size()))
        }
    },



    afterRender: function(e) {
        var tabview = this.get('host');
        tabview.get('contentBox').one('> ul').append(this.ADD_TEMPLATE);
    },

    onAddClick: function(e) {
        e.stopPropagation();
        var tabview = this.get('host'),
            input = this.getTabInput();
        tabview.add(input, input.index);
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文