javascript – 从ClientDetailTemplate中的ClientTemplate中访问行数据
作者:互联网
我在ASP.Net MVC 4应用程序中使用了Kendo UI Web Grid.
在下面代码的底部,您将看到一个名为GetEditChildUrl的JavaScript函数,它接受一个名为data的参数.不幸的是,作为数据参数传入的内容是父行数据,但我期待子行数据.这适用于GetEditParentUrl.那么如何获取子行数据呢?
@(Html.Kendo().Grid<Application.Models.Parent>()
.Name("grid_parent")
.Columns(columns =>
{
columns.Bound(x => x.Name);
columns.Bound(x => x).ClientTemplate(
"<a href='#= GetEditParentUrl(data) #' class='k-button' style='min-width:0px;'><span class='k-icon k-i-pencil'></span></a>"
).Width(90).Filterable(false);
})
.Scrollable(action => action.Virtual(true))
.Filterable()
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Parents_Read", "Parent"))
)
.Scrollable(s => s.Height("auto"))
.ClientDetailTemplateId("client-template")
)
@section Scripts {
<script id="client-template" type="text/x-kendo-template">
<h3>Contacts</h3>
@(Html.Kendo().Grid<Application.Models.Child>()
.Name("grid_child_#=Id#") // make sure the Name is unique
.Columns(columns =>
{
columns.Bound(x => x.Name);
columns.Bound(x => x).ClientTemplate(
"<a href='#= GetEditChildUrl(data) #' class='k-button' style='min-width:0px;'><span class='k-icon k-i-pencil'></span></a>"
).Width(90).Filterable(false);
})
.DataSource(dataSource =>
dataSource.Ajax().Read(read => read.Action("Children_Read", "Parent", new { parentId = "#=Id#" }))
)
.Scrollable(s => s.Height("auto"))
.Sortable()
.ToClientTemplate()
)
</script>
<script>
function GetEditParentUrl(data) {
return "@Url.Action("Edit", "Parent")/" + data.Id;
}
function GetEditChildUrl(data) {
return "@Url.Action("Edit", "Child")/" + data.Id;
}
</script>
}
解决方法:
尝试转义列客户端模板中的哈希(#)符号.
columns.Bound(x => x)
.ClientTemplate("<a href='\\#= GetEditChildUrl(data) \\#' ...>")
Important: The “#” characters used for a template expression should be
escaped when using a column ClientTemplate in a detail template so
that the expression is evaluated in the correct context.
标签:javascript,asp-net-mvc,kendo-ui,kendo-grid 来源: https://codeday.me/bug/20190825/1717715.html