我正在为MVC页面上的kendo网格实现上下文菜单.我正在尝试使用单击上下文菜单调用我的kendo网格上的编辑按钮.我已经在我的上下文菜单和事件编写的jquery代码上实现了事件来调用编辑按钮的click事件.我确实看到窗口弹出一瞬间关闭.我如何让这个工作
@(Html.Kendo().ContextMenu()
.Name("menu")
.Target("#GridTeam")
.Filter("tr")
.Orientation(ContextMenuOrientation.Vertical)
.Animation(animation =>
{
animation.Open(open =>
{
open.Fade(FadeDirection.In);
open.Duration(500);
});
})
.Items(items =>
{
items.Add()
.Text("Edit");
items.Add()
.Text("Delete");
})
.Events(e =>
{
e.Select("onEdit");
})
)
function onEdit(e) {
//Logic to be executed on Edit event
$('a.k-grid-edit').click();
Run Code Online (Sandbox Code Playgroud) jquery kendo-grid kendo-asp.net-mvc asp.net-mvc-5 kendo-contextmenu
我想在我的应用程序中使用 Kendo UI 上下文菜单。我期待在菜单本身中显示文本的标准行为,但将不同的值(ID 或键)返回给select事件处理程序。
例如,菜单显示了一个名称列表,但是当我单击其中一个时,我会得到与该名称相关联的 ID。
除了text上下文菜单中的项目数组之外,我尝试添加其他属性,但在处理程序的事件对象上没有看到它们。
我无法使用文本来查找与其匹配的适当 ID,因为可能存在具有相同文本但 ID 不同的条目。
有任何想法吗?
编辑:
目前我像这样构建上下文菜单:
open: (e) => {
let itemKeys = [1, 2, 3];
let menu = e.sender;
menu.remove(".context-menu-item");
menu.append(itemKeys.map((itemKey) => {
return {
text: "<div data-item-key='" + itemKey + "'>Test Text</div>",
cssClass: "context-menu-item",
encoded: false
};
}));
}
Run Code Online (Sandbox Code Playgroud)
虽然这个解决方案确实满足了我的需求,但它为 DOM 添加了一个额外的元素,虽然微不足道,但并不完美......