如何隐藏*single*MVC/Kendo tabstrip标签?

CLu*_*ays 1 javascript jquery telerik kendo-ui

如何在MVC/Kendo UI选项卡上隐藏单个选项卡?

我想根据条件隐藏选项卡.我的jQuery代码是这样的:


        //authUser is a hidden input whose value is set in the controller and passed into the view

        if ($('#authUser').val() == 'False') //hide the last tab
        {
            $($("#tabstrip").data("kendoTabStrip").items()[6]).attr("style", "display:none");
        }
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,如果authUser为False,则在执行的代码行上出现以下错误:

JavaScript运行时错误:无法获取未定义或空引用的属性"项"

想法?

Dre*_*yes 8

'items'未定义的事实意味着您从未在第一时间正确选择了tabstrip.您的CSS选择器是错误的(您确定将其命名为tabstrip吗?)或者您没有正确遵循Kendo方法名称.

以下是我发现隐藏最后一个标签的两种方法:

隐藏最后一个tabstrip元素

var tabStrip = $("#tabstrip").kendoTabStrip().data("kendoTabStrip");
//Find the last tab item's index from the items list
var lastIndex = tabStrip.items().length - 1;
//Use jQuery's hide method on the element
$(tabStrip.items()[lastIndex]).hide();
Run Code Online (Sandbox Code Playgroud)

使用Kendo的tabstrip删除方法

我相信以下更合适.为什么不使用tabstrip的remove方法并将其从DOM中完全删除,因为用户不应该有访问权限?

var tabStrip = $("#tabstrip").kendoTabStrip().data("kendoTabStrip");
tabStrip.remove("li:last");
Run Code Online (Sandbox Code Playgroud)