>我使用这样的例子:剑道和PHP教程
我在子网格中使用代码,就像在网格中使用代码一样:
subDS = new kendo.data.DataSource({
transport: {
read: "data/channelName.php?acc="+e.data.userId,
destroy: {
url: "data/chMove.php",
type: "DELETE",
complete: function (e) {
$("#grid").data("kendoGrid").dataSource.read();
}
}
},
error: function(e) {
alert(e.responseText);
},
schema: {
data: "results",
model: {
id: "channelId"
}
}
});
detailRow.find(".subgrid").kendoGrid({
dataSource: subDS,
columns: [
{
title: "Channel Name", field: "channelname"
},
{
command: ["destroy"], title: " ", width: "100px"
}]
});
但是,代码不会在 PHP 代码的服务器端触发,
我不确定是客户端代码错误还是服务器端错误?
读取是返回:
{"结果":[{"channelname":"test"},{"channelname":"5413trret"},{"channelname":"d453"},{"channelname":"test3"},{"channelname":"ter"},{"channelname":"test5"}]}
并且用户 ID 在网格的读取中。
服务器端(chMove.php)我尝试测试它是否被触发,使用如下警报:
<?php
// determine the request type
$verb = $_SERVER["REQUEST_METHOD"];
echo "<script>alert('"."123"."');</script>";
?>
但是警报永远不会被触发,不用说我想得到parse_str(file_get_contents('php://input'), $request );
稍后并解析$request。
最终目标是删除用户在"删除"按钮中单击的内容,服务器端可以在数据库中删除它。
对我的代码有任何想法吗?还是有没有其他方法可以删除子网格?
任何建议赞赏。
好的,我有替代方法。我看手册:下面显示如何触发删除功能
代码是这样的:
var detailRow = e.detailRow;
subDS = new kendo.data.DataSource({
transport: {
read: "data/channelName.php?acc="+e.data.userId
},
error: function(e) {
alert(e.responseText);
},
schema: {
data: "results",
model: {
id: "channelid",
fields: {
channelname:{ editable: false}
}
}
}
});
// create a subgrid for the current detail row, getting territory data for this employee
detailRow.find(".subgrid").kendoGrid({
columns: [
{ title: "Channel Name", field: "channelname"},
{ command: "destroy", title: " ", width: "100px" }
],
dataSource: subDS,
editable: true,
remove: function(e) {
//alert("Removing:" + e.model.channelid);
var xmlhttp2;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp2=new XMLHttpRequest();
} else {
xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp2.open("POST","data/chMove.php",true);
xmlhttp2.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp2.send("channel="+e.model.channelid);
}
});
最重要的是将子网格设置为可编辑(我之前没有设置属性),
id的模型可以让您在数据中使用("结果")。
我还展示了连接到PHP端:)的技巧
然后,您可以像往常一样处理服务器端:
(在 chMove.php)
$channel=mysql_real_escape_string($_POST["channel"]);
我花了很多时间来处理它,我希望它有所帮助。