我在项目中使用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 :(得分: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);
}
}