全都问候,
如果我的代码中有这个category.php文件执行CRUD功能。但在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();
}
},
},
最后循环后,我需要在我的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();
}
},
},