我对 kendoui 弹出网格编辑有疑问。当我从网格 parameterMap 中删除任何行时,不会将 ny 值返回到 php 文件。
我的 index.php 代码是
<!DOCTYPE html>
<html>
<head>
<title>CRUD Using Kendo</title>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js"></script>
<link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.common.min.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.default.min.css" rel="stylesheet" />
</head>
<body>
<div id="grid"></div>
<script type="text/x-kendo-template" id="productsEditTemplate">
<form action="employee.php" method="post">
<label for="price">firstname</label><input data-bind="value: FirstName" name="FirstName"/><br/>
<label for="discounted">LastName</label><input data-bind="value: LastName" name="LastName"/><br/>
<input type="hidden" name="pk_id" data-bind="value: pk_id" />
<input type="hidden" name="upload" id='uploadedFile' data-bind="value: image" />
<input type="file" id="files" data-role="upload"
data-async='{"saveUrl": "upload.php","autoUpload": "true"}' data-success="onSuccess" name="files" />
<input type="submit" value="update" />
</form>
</script>
<script type="text/x-kendo-template" id="template">
<div class="subgrid"></div>
</script>
<script>
var del = "employee.php?";
$(function() {
$("#grid").kendoGrid({
dataSource: {
transport: {
read: "employee.php",
update: {
url: "employee.php",
type: "POST"
},
destroy: {
url: "destroy.php",
type: "POST",
dataType:"json"
},
create: {
url: "create.php",
type: "POST"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
alert(options.pk_id);
return { data: {my: kendo.stringify(options.models)} };
}
}
},
pageSize: 10,
error: function(e) {
alert(e.responseText);
},
schema: {
data: "data",
model:{
id:"pk_id",
fields:{
FirstName: { editable: true },
LastName: { validation: { required: true} },
image:{type: "string",defaultValue: ""}
}
}
}
},
columns: [{ field: "FirstName",width: "100px" }, { field: "LastName",width: "50px" },{ command: [{text:"Edit", name:"edit"}, {text:"Delete", name:"destroy"}], title: " ", width: "110px" }],
width: 510,
toolbar: ["create"],
detailTemplate: kendo.template($("#template").html()),
detailInit: detailInit,
editable: {
mode: "popup",
template: kendo.template($("#productsEditTemplate").html())
},
height: 600,
filterable: true,
sortable: true,
pageable: {
input: true,
numeric: false
},
save: function(e,c){
e.model.set("image",$("#uploadedFile").val());
}
});
});
function onSuccess(e){
$("#uploadedFile").val(e.files[0].name);
}
function detailInit(e) {
// get a reference to the current row being initialized
var detailRow = e.detailRow;
// create a subgrid for the current detail row, getting territory data for this employee
detailRow.find(".subgrid").kendoGrid({
dataSource: {
transport: {
read: "terretories.php"
},
schema: {
data: "data"
},
serverFiltering: true,
filter: { field: "pk_id", operator: "eq", value:e.data.pk_id}
},
columns: [{ title: "Title", field: "title" },{ title: "Age", field: "age" },{ command: "destroy" }],
});
}
</script>
</body>
</html>
destroy1.php 是
<?php
header("Content-type: application/json");
$con = mysql_connect("localhost", "root", "");
if (!$con)
{
die('Could not connect: ' . mysql_error());
} else {
mysql_select_db("northwind") or die("Unable To Connect To Northwind");
$json = file_get_contents("php://input");
$verb = $_SERVER["REQUEST_METHOD"];
if ($verb == "POST") {
// $employeeId = mysql_real_escape_string($_GET["pk_id"]);
$data = json_decode($json, true);
$employeeId = $data[0]['pk_id'];
echo $data[0]['pk_id'];
// $employeeId = $json->pk_id;
$rs = mysql_query("DELETE FROM employees WHERE pk_id = " .$employeeId);
if ($rs) {
echo json_encode($rs);
}
else {
header("HTTP/1.1 500 Internal Server Error");
echo "Failed on delete: " .$employeeId;
}
}
mysql_close($con);
}
?>
现在我不明白为什么parametermap 没有向destroy.php 返回任何值?或者我的 php 文件中是否有任何语法错误?我很困惑请帮助我谢谢