剑道网格层次添加新的行-传递父ID到新的子记录
Kendo Grids Hierarchy Adding New Row - Pass Parent ID to New Child Record
我是剑道和javascript的新手,所以请原谅我的知识失误…下面我有一个基本的剑道等级网格。当我尝试向子网格添加新记录时,该记录通过我的控制器中的post方法添加,但父引用ID没有正确传递,而是0作为外键引用传递到子表。
这是我的父网格
//-----------------KENDO GRID DATA-----------------
var datasource = new kendo.data.DataSource({
type: "odata",
transport: {
read: {
//url: sBaseUrl,
url: baseUrl + "StationLogPaperTicketOdata",
type: "get",
dataType: "json",
contentType: "application/json"
},
update: {
type: "PUT",
url: function (data) {
return baseUrl + "StationLogPaperTicketOdata(" + data.log_id + ")";
},
dataType: "json",
},
//parameterMap: function(options, operation) {
// if (operation !== "read" && options.models) {
// return {models: kendo.stringify(options.models)};
// }
//}
},
schema: {
data: "value",
total: function (data) {
return data['odata.count'];
},
model: {
id: "log_id",
fields: {
log_id: { type: "number" },
log_station: { type: "string" },
log_sourceCode: { type: "string", nullable: true },
log_carrierName: { type: "string", nullable: true },
log_ticketNumber: { type: "string", nullable: true },
log_deliveryTS: { type: "date" },
log_leaseNumber: { type: "string", nullable: true },
log_leaseName: { type: "string", nullable: true },
log_type: { type: "string" },
log_rackNumber: { type: "number", nullable: true },
log_logNumber: { type: "number", nullable: true },
log_driverFirstName: { type: "string", nullable: true },
log_driverLastName: { type: "string", nullable: true },
log_linkedTicketNumber: { type: "string", nullable: true },
log_volumeGross: { type: "number" },
log_volumeNet: { type: "number", nullable: true },
log_originalDestination: { type: "string", nullable: true },
log_lastModifiedTS: { type: "date", editable: false },
log_lastModifiedBy: { type: "string", editable: false },
log_meterReadOpen: { type: "number", nullable: true },
log_volumeNetCalculated: { type: "number", nullable: true },
log_isDeleted: { type: "string", nullable: true },
log_detailIsDeleted: { type: "string", nullable: true },
log_paperTicketIsApproved: { type: "string", nullable: true, editable: false },
log_accountingDate: { type: "date", nullable: true },
log_stationNumber: { type: "string", nullable: true },
log_isPickup: { type: "string", nullable: true },
log_operatorNumber: { type: "string", nullable: true },
log_controlNumber: { type: "string", nullable: true },
log_dispatchConfirmationNumber: { type: "string", nullable: true },
log_groupId: { type: "number", nullable: true },
log_groupSource: { type: "string", nullable: true },
log_isTank: { type: "string", nullable: true },
log_meterReadClose: { type: "number", nullable: true },
log_obsTemperature: { type: "number", nullable: true },
log_tankTemperature: { type: "number", nullable: true },
log_obsGravity: { type: "number", nullable: true },
log_bswPercent: { type: "number", nullable: true },
log_gaugeBeforeUnloadFeet: { type: "number", nullable: true },
log_gaugeBeforeUnloadInches: { type: "number", nullable: true },
log_gaugeBeforeUnloadQuarter: { type: "number", nullable: true },
log_comments: { type: "string", nullable: true }
}
}
},
pageSize: 50,
serverPaging: true,
serverfilering: true,
serverSorting: true,
sort: { field: "log_id", dir: "asc" },
});
//-----------------KENDO GRID-----------------
$("#grid").kendoGrid({
dataSource: datasource,
pageable:
{
refresh: true,
pageSizes: [10,25,50,100],
buttonCount: 5
},
height: 600,
width: 500,
sortable: true,
scrollable: true,
reorderable: true,
toolbar: ["save", "cancel"],
editable: true,
filterable: {
mode: "row"
},
selectable: "row",
resizable: true,
detailInit: detailInit,
dataBound: onDataBound,
columns: [
//{ field: "log_id", title: "ID", width: 130 }, //THIS IS FOR TESTING PURPOSES
{
field: "log_paperTicketIsApproved",
title: "Approved",
width: 130,
template:
"# if(log_paperTicketIsApproved == 'Y') { #" +
"# approved = true #" +
"# } else { #" +
"# approved = false #" +
"# } #" +
"<input name='paperTicketIsApproved' class='check_row' type='checkbox' data-bind='checked: approved' #= approved ? checked='checked' : '' #/>"
},
{ field: "log_type", title: "Source", width: 130 },
{ field: "log_rackNumber", title: "Connect Point (LACT)", width: 150 },
{ field: "log_sourceCode", title: "Carrier Source Code", width: 140 },
{ field: "log_carrierName", title: "Carrier Name", width: 130 },
{ field: "log_ticketNumber", title: "Ticket Number", width: 130 },
{ field: "log_deliveryTS", title: "Date", width: 160, format: "{0:MM-dd-yyyy}" },
{ field: "log_deliveryTS", title: "Time", width: 140, format: "{0:hh:mm tt}" },
{ field: "log_volumeGross", title: "Gross BBLs", width: 140 },
{ field: "log_volumeNet", title: "Net BBLs", width: 140 },
{ field: "log_leaseName", title: "Lease Name", width: 200 },
{ field: "log_driverFirstName", title: "Driver First Name", width: 160 }, // template: "#= log_driverFirstName # #=log_driverLastName #" },
{ field: "log_driverLastName", title: "Driver Last Name", width: 160 },
{ field: "log_bswPercent", title: "Obs. BS&W %", width: 140 },
{ field: "log_obsGravity", title: "Obs. Gravity", width: 130 },
{ field: "log_obsTemperature", title: "Obs. Temperature", width: 150 },
{ field: "log_linkedTicketNumber", title: "Linked Ticket Number", width: 150 },
{ field: "log_originalDestination", title: "Original Destination", width: 150 },
{ field: "log_lastModifiedBy", title: "Last Modified By", width: 170 },
{ field: "log_lastModifiedTS", title: "Last Modified Date", width: 170, format: "{0:MM-dd-yyyy hh:mm tt}" },
//{ field: "log_station", title: "Station", width: 140 } //THIS IS FOR TESTING PURPOSES ONLY
]
});
var grid = $("#grid").data("kendoGrid");
//grid.bind("dataBound", onDataBound);
grid.table.on("click", ".check_row", selectRow)
}
这里是子网格
//-----------------KENDO CHILD-GRID DATA-----------------
function detailInit(e) {
var datasource = new kendo.data.DataSource({
type: "odata",
transport: {
read: {
url: baseUrl + "StationLogComments",
type: "get",
dataType: "json"
},
update: {
type: "put",
url: function (data) {
return baseUrl + "StationLogComments(" + data.log_commentID + ")";
},
dataType: "json",
contentType: "application/json"
},
create: {
url: baseUrl + "StationLogComments",
type: "post",
dataType: "json"
},
},
schema: {
data: "value",
total: function (data) {
return data['odata.count'];
},
model: {
id: "log_commentID",
fields: {
log_commentID: { type: "number" },
log_id: { type: "number" },
log_comment: { type: "string" },
log_commentCreatedBy: { type: "string" },
log_commentCreatedDate: { type: "date", editable: false }
}
}
},
serverPaging: true,
serverSorting: true,
sort: { field: "log_commentCreatedDate", dir: "asc" },
serverFiltering: true,
width: 100,
pageSize: 10,
filter: { field: "log_id", operator: "eq", value: e.data.log_id }
});
//-----------------KENDO CHILD-GRID-----------------
$("<div/>").appendTo(e.detailCell).kendoGrid({
dataSource: datasource,
scrollable: false,
toolbar: ["create", "save", "cancel"],
saveChanges: function (e) {
debugger;
},
editable: true,
resizable: true,
width: 600,
//sortable: true,
//pageable: true,
columns: [
{ field: "log_id", title: "log_id", width: "100px" },
{ field: "log_comment", title: "Comment", width: "500px" },
{ field: "log_commentCreatedBy", title: "Created By", width: "100px" },
{ field: "log_commentCreatedDate", title: "Created Date", format: "{0:MM-dd-yyyy hh:mm tt}" }
]
});
}
我可以把saveChanges:得到我想要的结果吗?由于
已解析!!
我找到了我自己的答案,我把它贴在这里,希望它可以帮助别人。
在我的子网格模型中,我将这行代码添加到外键引用:
defaultValue: e.data.log_id
现在我的子网格模型是这样的
model: {
id: "log_commentID",
fields: {
log_commentID: { type: "number" },
log_id: { type: "number", defaultValue: e.data.log_id },
log_comment: { type: "string" },
log_commentCreatedBy: { type: "string" },
log_commentCreatedDate: { type: "date", editable: false }
}
相关文章:
- 将一个表的id与另一个表中的user_id进行匹配,以获取mysql中的记录
- 包含插入的Meteor方法没有返回记录ID作为结果
- MongoDB 2.0.0 驱动程序,按 ID 检索记录时出现问题
- 如何获取具有指针字段的对象 ID 的记录
- YDN 数据库 按 ID 删除记录 (索引数据库)
- Jqgrid 使用 afterSubmit 事件获取新添加记录的 ID
- 在行单击时,将记录 ID 传递给引导模式中的链接按钮
- 搜索Ember数据async hasMany id而不加载所有id记录
- SailsJS-使用自定义ID创建新记录
- 简单的coldfusion将记录id传递给JS函数
- 如何获取由填充对象中的特定许可证 ID 创建的记录
- 不要在Sails.js的collection属性中按id记录排序
- MS CRM 2015使用JavaScript编辑并显示来自另一个实体记录iFrame的id自定义实体记录
- 通过id和其他参数查找Ember-data记录
- 复制具有唯一id的记录
- YDN-DB -如何通过id更新记录
- 在Angularjs的控制器中显示创建的记录Id
- Ng-options显示名称但记录id
- 在Javascript中记录按钮id
- 如果使用laravel框架,如何在javascript或ajax中传递用户id以从数据库中获取记录