问候所有
在我执行CRUD功能的代码中是否有这个category.php文件。但是,在Kendo UI dataSource中,如何在数据源/传输中调用这些函数? 在此之前,我曾经将php文件拆分过,但是现在我只想放入一个文件中。 谁能帮我?谢谢您的宝贵时间。
<?php
class Categories {
function getCategory(){
//codes in here
}
function addCategory(){
//codes in here
}
function editCategory(){
//codes in here
}
function deleteCategory(){
//codes in here
}
}
?>
transport: {
read: {
url: "./category.php", // <---calling getCategory function
type: "POST",
data: function() {
return {
c1: document.getElementById('c1').checked,
}
},
},
create: {
url: "./category.php", // <---calling addCategory function
type: "POST",
complete: function (e) {
$('#grid').data('kendoGrid').dataSource.read();
}
},
update: {
url: "./category.php", // <---calling editCategory function
type: "POST",
complete: function (e) {
$('#grid').data('kendoGrid').dataSource.read();
}
},
destroy: {
url: "./category.php", // <---calling deleteCategory function
type: "POST",
complete: function (e) {
$('#grid').data('kendoGrid').dataSource.read();
}
},
},
答案 0 :(得分:0)
最后一圈,我需要在我的php文件中添加method()
,然后在我的dataSource / transport上向该方法返回值data: {method: "addCategory"},
,例如下面的示例。
<?php
$method = $_POST['method'];
$method();
class Categories {
function getCategory(){
//codes in here
}
function addCategory(){
//codes in here
}
function editCategory(){
//codes in here
}
function deleteCategory(){
//codes in here
}
}
?>
transport: {
read: {
url: "category.php",
type: "POST",
data: function() {
return {
method: "getCategory",
c1: document.getElementById('c1').checked,
}
},
},
create: {
url: "category.php",
type: "POST",
data: {method: "addCategory"},
complete: function (e) {
$('#grid').data('kendoGrid').dataSource.read();
}
},
update: {
url: "category.php",
type: "POST",
data: {method: "editCategory"},
complete: function (e) {
$('#grid').data('kendoGrid').dataSource.read();
}
},
destroy: {
url: "category.php",
type: "POST",
data: {method: "deleteCategory"},
complete: function (e) {
$('#grid').data('kendoGrid').dataSource.read();
}
},
},