Kendo grid使用http post响应读取数据源

时间:2016-01-15 15:03:57

标签: angularjs kendo-ui kendo-grid

我是Kendo UI的新手,我使用数据表来显示值,这是我的旧代码(工作):

$http.post("/reports/api/g3swmf/report", $scope.g3sWmf ).success(function(data){
    $scope.reportVal += " - " + data;
}).then(function (response){
    $scope.items=response.data;   
}

这是Kendo UI版本(不工作):

$scope.g3sGridOptions = {
    toolbar: ["excel"],
    excel: {
        allPages: true
    },
    dataSource: {
        type: "json",
        transport: {
        read: {
            url:("/reports/api/g3swmf/report", $scope.g3sWmf ),
            type: "post",
            dataType: "json"
        }
    },
    schema: {
        model: {
            fields: {
                poloCode: { type: "string" },
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

剑道的传输网址应该是一个字符串。

url:"/reports/api/g3swmf/report"

$http.post没有处理相同的问题。实际上,它将read参数直接传递给jquery.ajax。

有两种方法可以解决这个问题。

  1. 使用字符串网址进行传输
  2. 将transport.read定义为函数。然后,您就可以将自己称为$http.post。如果你定义一个函数,请注意kendo将提供一个事件参数,其中包含一些应该用于将数据发送回网格的回调方法。
  3. 这是一个自定义阅读示例:

    read: function (readOptions) {
        $http.post("/reports/api/g3swmf/report", $scope.g3sWmf ).success(function(data){
            readOptions.success(data);
        })
    }
    

    有关详细信息,请参阅kendo dataSource API documentation

相关问题