2015-11-09 87 views
0

我在我的項目中使用kendo工具欄作爲菜單項。我有一個名爲「新」的菜單,在這之下有幾個子菜單。如何將自定義js函數添加到kendo工具欄按鈕?

我想添加一個函數來點擊子菜單,以便我可以相應地重定向頁面。這裏是我的代碼:

for (var i = 0; i < subMenues.length; i++) { 

      if (subMenues[i].Visible) { 

       var tObject = {}; 
       var imageSource = ResolveUrl(subMenues[i].Image); 
       var actionurl = ResolveUrl(subMenues[i].ActionURL); 

       tObject['text'] = "<img src='" + imageSource + "'/> " + subMenues[i].Name;      
       tObject['click'] = function (e) { 
        alert(i); 
       }; 

       //tObject['template'] = '#= ButtonClickHandler(1)#'; 
       items.push(tObject); 
      } 
     } 

     return items; 

但這裏的每一次我收到的i的最後一個索引是8

+0

你可以創建http://dojo.telerik.com一個簡單的例子? – DontVoteMeDown

回答

0

我得到了一個解決方案的子菜單中點擊。這裏是我的代碼,增加了客戶端功能

for (var i = 0; i < subMenues.length; i++) { 

      if (subMenues[i].Visible) { 

       var tObject = {}; 
       var imageSource = ResolveUrl(subMenues[i].Image); 
       var actionurl = ResolveUrl(subMenues[i].ActionURL); 

       tObject['text'] = "<img src='" + imageSource + "'/> " + subMenues[i].Name; 
       tObject['id'] = actionurl; 
       tObject['click'] = ButtonClickHandler; 

       items.push(tObject); 
      } 
     } 
相關問題