Telerik MVC 层次结构网格、编辑器弹出窗口、在 JavaScript 事件中获取父数据
Telerik MVC hierarchy grid, editor popup, get parent data in JavaScript event
我进行了大量搜索,似乎找不到任何有效的示例。
我将在这里简化代码,因为我有一个非常大的 telerik mvc 层次结构网格。这是下几级的子模板,我需要上一级的父级信息。
<script id="leagueTemplate" type="text/kendo-tmpl">
@(Html.Kendo().Grid<LeagueViewModel>()
.Name("grid_#=LeagueTypeId#")
.ToolBar(toolbar =>
{
toolbar.Create().Text("Add New League(Window)");
})
.Events(e => e.Edit("leagueEdit")) // this function runs
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.LeagueID))
.Read(read => read.Action("Bound_League_Read", "Configuration", new { _leagueTypeId = "#=LeagueTypeId#" }))
.Create(create => create.Action("League_Create", "Configuration").Data("getHeirarchyData")) // this function doesnt run
)
)
</script>
function getHeirarchyData() {
console.log("get heirachy data"); // never runs
}
function leagueEdit(e) {
// this runs
// not sure how to get parent data from e
}
可能有更好的方法来解决这个问题,如果是这样,我会检查你的答案,但同时这可能会对某人有所帮助。
我通过为模型设置默认值解决了这个问题,除了字符串值之外,它工作得很好,因为我必须以模板语法字符串的方式访问这些值。所以我只是将我的层次结构字段的字符串值等价物添加到模型中。
.Model(model =>
{
model.Id(p => p.LeagueID);
model.Field(l => l.strSportId).DefaultValue("#=SportId#");
model.Field(l =>
l.strLeagueTypeId).DefaultValue("#=LeagueTypeId#");
}
)
然后当我调用编辑函数时,我可以得到这样的值:
function leagueEdit(e) {
var sportId = parseInt(e.model.strSportId);
var leagueTypeId = parseInt(e.model.strLeagueTypeId);
}
我进行了大量搜索,似乎找不到任何有效的示例。
我将在这里简化代码,因为我有一个非常大的 telerik mvc 层次结构网格。这是下几级的子模板,我需要上一级的父级信息。
<script id="leagueTemplate" type="text/kendo-tmpl">
@(Html.Kendo().Grid<LeagueViewModel>()
.Name("grid_#=LeagueTypeId#")
.ToolBar(toolbar =>
{
toolbar.Create().Text("Add New League(Window)");
})
.Events(e => e.Edit("leagueEdit")) // this function runs
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.LeagueID))
.Read(read => read.Action("Bound_League_Read", "Configuration", new { _leagueTypeId = "#=LeagueTypeId#" }))
.Create(create => create.Action("League_Create", "Configuration").Data("getHeirarchyData")) // this function doesnt run
)
)
</script>
function getHeirarchyData() {
console.log("get heirachy data"); // never runs
}
function leagueEdit(e) {
// this runs
// not sure how to get parent data from e
}
可能有更好的方法来解决这个问题,如果是这样,我会检查你的答案,但同时这可能会对某人有所帮助。
我通过为模型设置默认值解决了这个问题,除了字符串值之外,它工作得很好,因为我必须以模板语法字符串的方式访问这些值。所以我只是将我的层次结构字段的字符串值等价物添加到模型中。
.Model(model =>
{
model.Id(p => p.LeagueID);
model.Field(l => l.strSportId).DefaultValue("#=SportId#");
model.Field(l =>
l.strLeagueTypeId).DefaultValue("#=LeagueTypeId#");
}
)
然后当我调用编辑函数时,我可以得到这样的值:
function leagueEdit(e) {
var sportId = parseInt(e.model.strSportId);
var leagueTypeId = parseInt(e.model.strLeagueTypeId);
}