简体   繁体   English

如何隐藏*单个* MVC/Kendo tabstrip 选项卡?

[英]How to hide a *single* MVC/Kendo tabstrip tab?

How do I hide a single tab on a MVC/Kendo UI tabstrip?如何在 MVC/Kendo UI 标签条上隐藏单个标签?

I want to hide a tab based on a condition.我想根据条件隐藏选项卡。 My jQuery code goes like this:我的 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");
        }

When I run the code I get the following error on the line of code that's executed if authUser is False:当我运行代码时,如果 authUser 为 False,我会在执行的代码行上收到以下错误:

JavaScript runtime error: Unable to get property 'items' of undefined or null reference JavaScript 运行时错误:无法获取未定义或空引用的属性“items”

Ideas?想法?

The fact that 'items' is undefined implies that you never appropriately selected the tabstrip in the first place. 'items' 未定义这一事实意味着您从一开始就没有适当地选择标签条。 Either your CSS selector is wrong (are you sure you named it tabstrip?) or you did not follow the Kendo method names appropriately.要么您的 CSS 选择器错误(您确定将其命名为 tabstrip?),要么您没有正确遵循 Kendo 方法名称。

Here are two ways I found to hide the last tab:这是我发现隐藏最后一个选项卡的两种方法:

Hiding the last tabstrip element隐藏最后一个 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();

Using Kendo's tabstrip remove method使用 Kendo 的 tabstrip remove 方法

I believe the following is more appropriate.我认为以下更合适。 Why not use the tabstrip's remove method and completely remove it from the DOM since the user should not have access anyway?为什么不使用 tabstrip 的 remove 方法并将其从 DOM 中完全删除,因为用户无论如何都不应该具有访问权限?

var tabStrip = $("#tabstrip").kendoTabStrip().data("kendoTabStrip");
tabStrip.remove("li:last");

I'm just stupid.... I looked some more at the code and I was leaving out the kendoTabStrip() word (bolded) from我只是愚蠢......我看了一些代码,我从

$($("#tabstrip"). kendoTabstrip() .data("kendoTabStrip").items()[6]).attr("style","display:none") $($("#tabstrip"). kendoTabstrip() .data("kendoTabStrip").items()[6]).attr("style","display:none")

ie Instead of (properly) having:即而不是(正确地)具有:

$($("#tabstrip").kendoTabStrip().data("kendoTabStrip").items()[6]).attr("style","display:none") 

I had:我有:

$($("#tabstrip").data("kendoTabStrip").items()[6]).attr("style","display:none") 

Drew, thanks for your effort.德鲁,谢谢你的努力。 Sometimes I just have to beat my head on a wall until I see what I've done.有时我只需要在墙上敲我的头,直到我看到我做了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM