【问题标题】:Kendo UI dataSource transport calling php functionKendo UI dataSource 传输调用 php 函数
【发布时间】:2019-03-18 03:49:43
【问题描述】:

大家好,

如果我的代码中有这个 category.php 文件来执行 CRUD 功能。但是在 Kendo UI 数据源中,我如何在数据源/传输中调用这些函数? 在此之前我曾经拆分过 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】:

    最后一圈后,我需要在我的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();
              } 
      },                
    },
    

    【讨论】:

      猜你喜欢
      • 2013-04-03
      • 2013-10-24
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-08
      • 1970-01-01
      相关资源
      最近更新 更多