2014-02-27 75 views
1

我正在使用kendo UI菜單。 我已經喜歡顯示選中的菜單項必須在父項中顯示

$("#menu").kendoMenu({ 
    dataSource: [ 
      { text: "parent", 
       items: [ 
           { text: "child1" }, 
           { text: "child2" }, 
           { text: "child3" }, 
           { text: "child4" } 
          ] 
       }  
      ], 
     select:function(e){ 
      $(e.item).children(".k-link").text(); 
     } 
    }); 

定義開始菜單中顯示的文字爲「父」。 我想要的是,在選擇事件中,當我點擊任何其他項目時,所選項目文本必須顯示在頂層菜單中。告訴我如何更改kendo菜單中的文本

回答

2

儘管menu使用DataSource來構建初始內容,但它不再使用,DataSource中的任何操作都不會直接反映在Menu中。這意味着你必須操縱DOM對象來替換文本。

// Get selected text 
var text = $(e.item).text(); 
// Get the first parent (in case you have multiple menu levels) 
var topParent = $(e.item).parents("li").last(); 
// And now go to the node that contains the text 
var textParent = $("> span.k-link", topParent); 
// Go to the content (text) and replace it with child text 
textParent.contents().first()[0].textContent = text; 

看到它在這裏的行動:http://jsfiddle.net/OnaBai/kfcdF/