Kendo UI dataSource传输调用php函数

问题描述 投票:1回答:1

全都问候,

如果我的代码中有这个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();
              } 
  },                
},
javascript php kendo-ui kendo-grid kendo-datasource
1个回答
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();
          } 
  },                
},
© www.soinside.com 2019 - 2024. All rights reserved.