我有2个kendoUI网格从网络服务做CRUD。出于某种原因,read命令工作正常并填充我的网格。但是在UserEventGrid()方法中没有触发创建。 这是我目前的情况。我有一个首先显示的网格。当我单击添加时,当我从该网格中选择一个项目时,它会打开一个查找网格,它会打开一个包含所选行的窗口。有 添加按钮。现在当我点击这个添加传输时:创建不会被触发。
UserEventGrid()这是主要的Grid [First Grid]。这有addentry按钮(它触发addEntry(e)) namesListGrid()这是单击查找后填充的第二个网格。在新窗口中选择行后,它有添加按钮。(它触发add(dataItem)和相应的传输。这就是 问题。它没有触发传输Create。
以下是我的代码。
function UserEventGrid() {
userDS = new kendo.data.DataSource({
type: "json",
schema: {
data: function (response) {
return JSON.parse(response.d);
},
model: {
id: "UserId",
fields: {
UserId: { editable: false, nullable: false, type: "string" },
FirstName: { editable: true, nullable: true, type: "string" },
LastName: { editable: true, nullable: true, type: "string" },
},
},
transport: {
read: {
url: "/Services/Services.asmx/getUsers",
contentType: "application/json; charset=utf-8",
type: "POST",
},
create: {
url: "/Services/Services.asmx/AddUsers",
contentType: "application/json; charset=utf-8",
type: "POST",
datatype: "json"
},
update: {
url: "/Services/Services.asmx/UpdateUsers",
contentType: "application/json; charset=utf-8",
type: "POST",
datatype: "json"
},
destroy: {
url: "/Services/Services.asmx/DeleteUsers",
contentType: "application/json; charset=utf-8",
type: "POST",
datatype: "json"
},
parameterMap: function (data, type) {
if ((type == "update") || (type == "create") || (type == "destroy")) {
console.log('parameterMap: data => ' + JSON.stringify(data));
return JSON.stringify({ "erpUserJson": data });
} else {
return data;
}
}
}
});
userGrid = $("#user-event-grid").kendoGrid({
dataSource: userDS,
height: 450,
pageable: false,
sortable: true,
autosync: true,
binding: true,
columns: [
{
field: "Active",
title: "Active",
headerTemplate: '<span class="tbl-hdr">Active</span>',
template: '<input type="checkbox" #= Active ? "checked=checked" : "" # disabled="disabled" ></input>',
attributes: {
style: "vertical-align: top; text-align: left; font-weight:bold; font-size: 12px"
},
width: 65
},
{
field: "FirstName",
title: "FirstName",
headerTemplate: '<span class="tbl-hdr">FirstName</span>',
attributes: {
style: "vertical-align: top; text-align: left; font-weight:bold; font-size: 12px"
}
},
{
field: "LastName",
title: "LastName",
headerTemplate: '<span class="tbl-hdr">LastName</span>',
attributes: {
style: "vertical-align: top; text-align: left; font-weight:bold; font-size: 12px"
}
},
,
{
command: [
{
name: "destroy",
template: "<div class='k-button delete-btn'><span class='k-icon k-delete'></span></div>",
text: "remove"
},
{
text: "Edit",
template: "<div class='k-button edit-btn'><span class='k-icon k-edit'></span></div>",
click: editEntry
},
],
width: 90,
attributes: {
style: "vertical-align: top; text-align: center;"
}
},
],
editable: "popup"
}).data('kendoGrid');
}
function namesListGrid() {
nameDS = new kendo.data.DataSource({
type: "json",
schema: {
data: function (response) {
return JSON.parse(response.d);
},
model: {
id: "Z_CIM_WRK_ID",
fields: {
Z_NAMEFIRST: { editable: false, nullable: false, type: "string" },
Z_NAMELAST: { editable: false, nullable: true, type: "string" },
EMAILID: { editable: false, nullable: true, type: "string" },
}
},
},
transport: {
read: {
url: "/Services/Services.asmx/getNames",
contentType: "application/json; charset=utf-8",
type: "POST",
datatype: "json",
data: getSearchCriteria()
},
parameterMap: function (data, type) {
if ((type == "read") || (type == "create") || (type == "destroy")) {
console.log("parametermap => " + JSON.stringify(data));
return JSON.stringify(data);
} else {
return data;
}
}
}
});
namesGrid = $("#second").kendoGrid({
dataSource: nameDS,
height: 450,
pageable: false,
sortable: true,
binding: true,
selectable: "row",
serverFiltering: true,
autoSync: true,
columns: [
{
field: "Z_EID",
title: "ID",
headerTemplate: '<span class="tbl-hdr">ID</span>',
attributes: {
style: "vertical-align: top; text-align: left; font-weight:bold; font-size: 12px"
}
},
{
field: "Z_NAMELAST",
title: "ZNAMELAST",
headerTemplate: '<span class="tbl-hdr">ZNAMELAST</span>',
attributes: {
style: "vertical-align: top; text-align: left; font-weight:bold; font-size: 12px"
}
},
{
field: "Z_NAMEFIRST",
title: "ZNAMEFIRST",
headerTemplate: '<span class="tbl-hdr">ZNAMEFIRST</span>',
attributes: {
style: "vertical-align: top; text-align: left; font-weight:bold; font-size: 12px"
}
},
],
change: function (e) {
var dataItem = this.dataItem(this.select());
$("#third").hide(true);
$("#second").hide(true);
$("#first").show(true);
$("#gtable").show(true);
add(dataItem);
}
}).data('kendoGrid');
}
function add(dataItem) {
console.log(JSON.stringify(dataItem));
var model = {
"UserId": dataItem.Z_EID,
"FirstName": dataItem.Z_NAMEFIRST,
"LastName": dataItem.Z_NAMELAST,
"Group": "OPS",
"EmailAddr": dataItem.EMAILID,
"MobilePhone": dataItem.PHONE,
};
var viewModel = kendo.observable({
data: model,
isAddMode: true,
isLookupMode:false,
isEditMode: false,
groups: userGroups,
closeWin: function (dataItem) {
console.log('data => ' + JSON.stringify(this.data));
console.log("BEFORE => " + JSON.stringify(userDS.data()));
userDS.add(this.data);
userDS.sync();
var editWin = $("#window");
editWin.data("kendoWindow").close();
},
});
kendo.bind($("#edit-win"), viewModel);
$("#palette").html('');
$("#palette").append('<div id="palette-widget"></div>');
$('#window').data("kendoWindow").center().open();
}
function addEntry(e) {
var model = {
"UserId": "",
"FirstName": '',
"LastName": '',
};
var viewModel = kendo.observable({
data: model,
isAddMode: false,
isLookupMode:true,
isEditMode: false,
filterable:true,
groups: userGroups,
closeWin: function (e) {
console.log('data => ' + JSON.stringify(this.data));
userDS.add(this.data);
var editWin = $("#window");
editWin.data("kendoWindow").close();
e.preventDefault();
},
LookupWin: function (e) {
namesListGrid();
},
});
kendo.bind($("#edit-win"), viewModel);
$("#palette").html('');
$("#palette").append('<div id="palette-widget"></div>');
$('#window').data("kendoWindow").center().open();
}
答案 0 :(得分:0)
在addEntry
函数中,您确实将数据添加到dataSource,如下所示:
userDS.add(this.data);
但是,您从不致电userDS.sync()
(您在add
功能但不是addEntry
)。您确实将autosync
属性设置为true,这将触发创建事件,但不是在userDS
dataSource上执行,而是在userGrid
上执行。您可以在autosync
dataSource中将userDS
设置为true,也可以在userDS.sync()
之后调用userDS.add
。