我目前正在开发一个项目,在该项目中我将 Spring MVC 与 Kendo UI jQuery 库(最新版本)结合使用。我遇到的问题是本地和远程更新剑道网格的数据源(剑道数据源)。我使用了数据源对象的同步和设置方法,但这些都不起作用。
我的 jQuery 代码:
/*global $:false */
$(document).ready(function () {
"use strict";
var request;
$("#tabstrip").kendoTabStrip();
var applicationDataSource = new kendo.data.DataSource({
transport: {
read: {
url: "/appinfo/findApplications",
dataType: "json"
},
create: {
url: "/appinfo/submit",
dataType: "json",
type: "POST"
},
update: {
url: "/appinfo/updateApplication",
dataType: "json",
type: "POST"
},
destroy: {
url: "/appinfo/deleteApplication",
dataType: "json"
},
schema: {
model: {
id: "applicationId",
fields: {
applicationId: {type: "number"},
applicationName: {type: "string"},
url: {type: "string"},
serverName: {type: "string"},
environmentName: {type: "string"},
ipAddress: {type: "string"},
genericUserName: {type: "string"},
genericPassword: {type: "string"}
}
}
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
if (operation == "destroy" && options.models) {
console.log("Delete worked");
return { models: kendo.stringify(data.models) };
}
}
},
batch: true,
pageSize: 10
});
var applicationGrid = $("#applicationsGrid").kendoGrid({
dataSource: applicationDataSource,
pageable: true,
height: 600,
scrollable: true,
sortable: true,
filterable: true,
toolbar: [
{name: "create", text: "Add New Application"}
],
columnMenu: true,
editable: {
update: true,
destroy: true,
create: true,
mode: "inline",
confirmation: "Are you sure you want to delete this record?"
},
columns: [
{field: "applicationName", title: "Application Name"},
{field: "url", title: "URL"},
{field: "serverName", title: "Server", editor: serverDropDownEditor, width: "300px"},
{field: "environmentName", title: "Environment", editor: environmentDropDownEditor, width: "300px"},
{field: "ipAddress", title: "Database", editor: databaseIpAddressDropDownEditor, width: "300px"},
{field: "genericUserName", title: "Default Username"},
{field: "genericPassword", title: "Default Password"},
{title: "Modify", command: ["edit" , "destroy"]}
],
edit: function (e) {
var dataItem = applicationDataSource.at(e.currentTarget);
console.log("DataSource Count: " + applicationDataSource.total());
},
save: function (e) {
var dataItem = applicationDataSource.at(e.currentTarget);
console.log("DataSource Count: " + applicationDataSource.total());
console.log("The model on save: " + e.model.applicationName);
applicationDataSource.sync();
},
create: function (e) {
console.log("Create this: " + e.values);
applicationDataSource.insert(e.model);
applicationDataSource.sync();
},
delete: function (e) {
console.log("Delete this: " + e.model);
applicationDataSource.remove(e.model);
}
});
function serverDropDownEditor(container, options) {
$('<input required data-text-field="serverName" data-value-field="serverId" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
optionLabel: " - Select - ",
dataTextField: "serverName",
dataValueField: "serverId",
dataSource: {
transport: {
read: {
url: "/appinfo/findServers",
dataType: "json"
}
}
}
});
}
function environmentDropDownEditor(container, options) {
$('<input required data-text-field="environmentName" data-value-field="environmentId" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
optionLabel: " - Select - ",
dataTextField: "environmentName",
dataValueField: "environmentId",
dataSource: {
transport: {
read: {
url: "/appinfo/findEnvironments",
dataType: "json"
}
}
}
});
}
function databaseIpAddressDropDownEditor(container, options) {
$('<input required data-text-field="ipAddress" data-value-field="databaseInfoId" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
optionLabel: " - Select - ",
dataTextField: "ipAddress",
dataValueField: "databaseInfoId",
dataSource: {
transport: {
read: {
url: "/appinfo/findDatabases",
dataType: "json"
}
}
}
});
}
});
顺便说一句....我正在使用最新版本的 Kendo-UI Web。