2014-05-07 19 views
1

如何隱藏MVC/Kendo UI選項卡上的單個選項卡?如何隱藏* single * MVC/Kendo tabstrip選項卡?

我想隱藏基於條件的選項卡。我的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"); 
     } 

當我運行代碼,我得到多數民衆贊成執行的代碼行下面的錯誤,如果AUTHUSER爲False:

的JavaScript運行時錯誤:無法獲取財產「項目'未定義或空引用

想法?

回答

6

'items'未定義的事實意味着您從未正確選擇過tabstrip。您的CSS選擇器是錯誤的(您確定您將它命名爲tabstrip?),或者您沒有適當地遵循Kendo方法名稱。

這裏有兩種方法,我發現隱藏的最後一個標籤:

隱藏的最後一個標籤欄元素

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(); 

使用劍道的標籤欄remove方法

我相信以下是更合適。爲什麼不使用tabstrip的remove方法並將其從DOM完全移除,因爲用戶不應該訪問?

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

如果您使用第一種方法,請確保檢查該選項卡是否被選中,如果是,請選擇另一個選項卡。如果隱藏的選項卡是活動選項卡,則內容仍將顯示在選項卡面板中,直到激活其他選項卡。 – aethercowboy

1

我只是愚蠢.... 我看了一些更多的代碼,我是從

$($( 「#分頁列」,留下了kendoTabStrip()字(加粗) 。)kendoTabstrip()。數據( 「kendoTabStrip」)項目()[6])ATTR( 「風格」,。。 「顯示:無」)

即相反的(正常),其具有:

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

我有:

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

德魯,謝謝你的努力。有時我只能在牆上打我的頭,直到我看到我做了什麼。