【发布时间】:2013-08-13 02:34:03
【问题描述】:
我是 kendo.ui 的初学者,我编写了这段代码来创建 kendo.ui.grid
@(Html.Kendo().Grid<BrandViewModel>(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.BrandName);
columns.Bound(p => p.BrandAbbr);
columns.Bound(p => p.SrcImage);
columns.Command(command => command.Custom("Edit").Click("editItem"));
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("CustomCommand_Read", "Brand"))
.Model(model => model.Id(p => p.Id))
)
)
当用户单击网格中的编辑按钮时,它将在 kendo.ui.window 中显示编辑视图,用户可以编辑数据。
@(Html.Kendo().Window().Name("Details")
.Title("Customer Details")
.Visible(false)
.Modal(true)
.Height(400)
.Draggable(true)
.Width(300)
.Events(events => events.Close("onClose"))
)
<script type="text/x-kendo-template" id="template">
<div id="details-container">
<!-- this will be the content of the popup -->
BrandName: <input type='text' value='#= BrandName #' />
</div>
</script>
<script type="text/javascript">
var detailsTemplate = kendo.template($("#template").html());
var windowObject;
$(document).ready(function () {
windowObject = $("#Details").data("kendoWindow");
});
function editItem(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
windowObject.refresh({
url: "/Brand/Edit/" + dataItem.Id
});
windowObject.center().open();
}
function onClose(e) {
var grid = $("#Grid").data("kendoGrid").dataSource.read();
}
</script>
但是在onClose 方法中$("#Grid").data("kendoGrid") 是未定义的,请帮助我,谢谢大家
【问题讨论】:
-
完全随机猜测...在 .Name("Grid") 和 .ID("Grid") 之后
-
@Robert Levy:ID 是 kendo.ui.grid 中未定义的属性。
-
你确定 $('#Grid').length 返回 > 0?
-
将
debugger;添加到您的 onClose() 方法中,然后在控制台中尝试 $('#Grid') ,确保返回您期望的元素。然后在控制台中尝试 $('#Grid').data() 。继续以这种方式调试。 -
你解决过这个问题吗?我有同样的问题 atm :/
标签: asp.net-mvc kendo-ui kendo-grid kendo-asp.net-mvc