Kendo UI dataSource传输调用php函数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kendo UI dataSource传输调用php函数相关的知识,希望对你有一定的参考价值。
全都问候,
如果我的代码中有这个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();
}
},
},
以上是关于Kendo UI dataSource传输调用php函数的主要内容,如果未能解决你的问题,请参考以下文章
Kendo UI Grid/DataSource - 全局错误处理?
AngularJS +Kendo UI Grid template
Kendo UI MVC 从 MultiSelect 小部件将 Grid 绑定到 DataSource