我有一个剑道 UI 网格并从 ajax 调用方法加载数据。第一次单击按钮时,数据加载没有任何问题,但是当我再次单击按钮时,数据未加载。有什么问题。请帮我。
<body>
<div id="example">
<button id="primaryTextButton" class="k-primary">Submit</button>
<div id="grid"></div> </div>
</body>
$(document).ready(function () {
var crudServiceBaseUrl = "http://demos.telerik.com/kendo-ui/service",
dataSource = new kendo.data.DataSource({
transport: {
/*read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},*/
read: function(options) {
$.ajax({
type: "POST",
url: crudServiceBaseUrl + "/Products",
// contentType: "application/json; charset=utf-8",
dataType: 'jsonp',
//data: JSON.stringify({key: "value"}),
// data: JSON.stringify(_traceInput),
success: function(data) {
var grid = $('#grid').getKendoGrid();
if (grid == undefined) {
grid.empty();
}
else {
grid.dataSource.data(data);
grid.refresh();
}
}
});
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
autoBind : false,
pageable: true,
height: 550,
toolbar: ["create"],
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "120px" },
{ field: "UnitsInStock", title:"Units In Stock", width: "120px" },
{ field: "Discontinued", width: "120px" },
{ command: ["edit", "destroy"], title: " ", width: "200px" }],
editable: "inline"
});
$('.k-primary').click(function (e) {
// do something else
dataSource.read();
});
});