2014-02-27 164 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/