为什么`data(“kendogrid")`未定义? [英] Why Is `data(“kendogrid”)` Undefined?
问题描述
我是 kendo.ui 的初学者,我编写了这段代码来创建 kendo.ui.grid
@(Html.Kendo().Grid(模型).Name("网格").Columns(columns =>{column.Bound(p => p.BrandName);column.Bound(p => p.BrandAbbr);column.Bound(p => p.SrcImage);columns.Command(command => command.Custom("Edit").Click("editItem"));}).DataSource(dataSource => 数据源.Ajax().Read(read => read.Action("CustomCommand_Read", "Brand")).Model(model => model.Id(p => p.Id))))
当用户单击网格中的编辑按钮时,它会在 kendo.ui.window 中显示编辑视图,用户可以编辑数据.
@(Html.Kendo().Window().Name("详情").Title("客户详情").可见(假).模态(真).高度(400).Draggable(真).宽度(300).Events(events => events.Close("onClose")))<script type="text/x-kendo-template" id="template"><div id="details-container"><!-- 这将是弹出窗口的内容-->品牌名称:<input type='text' value='#= BrandName #'/>
<script type="text/javascript">var detailsTemplate = kendo.template($("#template").html());var windowObject;$(document).ready(function () {windowObject = $("#Details").data("kendoWindow");});功能编辑项(e){e.preventDefault();var dataItem = this.dataItem($(e.currentTarget).closest("tr"));windowObject.refresh({网址:/品牌/编辑/"+ dataItem.Id});windowObject.center().open();}函数 onClose(e) {var grid = $("#Grid").data("kendoGrid").dataSource.read();}
但是在 onClose
方法中 $("#Grid").data("kendoGrid")
是未定义的,请帮助我,谢谢大家
尝试窗口加载事件
$(window).load(function () {var grid = $("#grid").data("kendoGrid");
这对我有用.
I'm a starter in kendo.ui, I've written this code to create 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))
)
)
When the user clicks the edit button in grid it will show Edit view in kendo.ui.window and the user can edit data.
@(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>
but in onClose
method $("#Grid").data("kendoGrid")
is Undefined, please help me, thanks all
try Window load event
$(window).load(function () {
var grid = $("#grid").data("kendoGrid");
this work for me.
这篇关于为什么`data(“kendogrid")`未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!