官方给的模板都是左侧导航菜单点击后,就路由到新的页面,这样很不方便,所以在下想实现的是,左侧点击,右侧会新建一个tab。tabpage之间可以进行切换。
初步思路是绑定数据,然后新建时通过post路由后台获取html,html渲染无异常
现在有个问题是,JavaScript代码无法使用
比如我点击新建菜单,然后会生成一个tabpage,这个tabpage是通过jQuery post方法获取 ~/menus/index的内容,
~/menus/index对应的cshtml的代码如下:
[C#] 纯文本查看 复制代码 @using DevExtreme.AspNet.Mvc;
@{
ViewData["Title"] = "菜单管理";
}
<div id="tree-list-menus">
<div>@ViewData["Title"]</div>
@(Html.DevExtreme().TreeList<XCERPNetCore.Models.Menus>()
.ID("employees")
.DataSource(ds => ds.Mvc()
.Controller("TreeListEmployees")
.LoadAction("Get")
.UpdateAction("Put")
.InsertAction("Post")
.DeleteAction("Delete")
.Key("ID")
)
.KeyExpr("ID")
.ParentIdExpr("HeadID")
.ShowRowLines(true)
.ShowBorders(true)
.Editing(editing => editing
.Mode(GridEditMode.Form)
.AllowUpdating(true)
.AllowDeleting(new JS("MenusTreeList_AllowDeleting"))
.AllowAdding(true)
)
.Columns(columns =>
{
columns.AddFor(m => m.Id);
columns.AddFor(m => m.Name);
columns.AddFor(m => m.SortInt);
columns.AddFor(m => m.Path);
columns.AddFor(m => m.Icon);
columns.AddFor(m => m.Path)
.Width(150);
columns.Add()
.Type(TreeListCommandColumnType.Buttons)
.Buttons(b =>
{
b.Add().Name(TreeListColumnButtonName.Edit);
b.Add().Name(TreeListColumnButtonName.Delete);
});
})
.ColumnAutoWidth(true)
.OnEditorPreparing("MenusTreeList_onEditorPreparing")
.OnInitNewRow("MenusTreeList_onInitNewRow")
.ColumnChooser(cc =>
{
cc
.Enabled(true)
.Mode(GridColumnChooserMode.Select)
.Position(pc => pc
.My(HorizontalAlignment.Right, VerticalAlignment.Top)
.At(HorizontalAlignment.Right, VerticalAlignment.Bottom)
.Of(".dx-treelist-column-chooser-button")
);
cc.Search(ccs => ccs
.Enabled(true)
.EditorOptions(new { Placeholder = "Search column" })
);
cc.Selection(ccs => ccs
.AllowSelectAll(true)
.SelectByClick(true)
.Recursive(true)
);
})
.ExpandedRowKeys(new[] { 1, 2, 3, 4, 5 })
)
<script type="text/javascript">
function MenusTreeList_onEditorPreparing(e) {
if (e.dataField === "HeadID" && e.row.data.ID === 1) {
e.editorOptions.disabled = true;
e.editorOptions.value = null;
}
}
function MenusTreeList_onInitNewRow(e) {
e.data.HeadID = 1;
}
function MenusTreeList_AllowDeleting(e) {
return e.row.data.ID !== 1;
}
</script>
</div>
post过程通过f12开发者工具调试发现会报错,报错信息是MenusTreeList_AllowDeleting对象找不到。
这个怎么办?求大佬帮助,感谢
|