Kendo 带有 http post 响应的网格读取数据源
Kendo grid read datasource with http post response
我是 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" },
}
}
}
}
kendo 的传输 url 假设是一个字符串。
url:"/reports/api/g3swmf/report"
它的处理方式与 $http.post
不同。其实就是把读取的参数直接传给了jquery.ajax.
有两种方法可以解决这个问题。
- 使用字符串 url 作为传输方式
- 将您的 transport.read 定义为函数。然后你就可以称呼你自己的
$http.post
。如果您定义一个函数,请注意 kendo 将提供一个事件参数和一些回调方法,这些回调方法应该用于将数据发送回网格。
这是一个自定义阅读示例:
read: function (readOptions) {
$http.post("/reports/api/g3swmf/report", $scope.g3sWmf ).success(function(data){
readOptions.success(data);
})
}
我是 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" },
}
}
}
}
kendo 的传输 url 假设是一个字符串。
url:"/reports/api/g3swmf/report"
它的处理方式与 $http.post
不同。其实就是把读取的参数直接传给了jquery.ajax.
有两种方法可以解决这个问题。
- 使用字符串 url 作为传输方式
- 将您的 transport.read 定义为函数。然后你就可以称呼你自己的
$http.post
。如果您定义一个函数,请注意 kendo 将提供一个事件参数和一些回调方法,这些回调方法应该用于将数据发送回网格。
这是一个自定义阅读示例:
read: function (readOptions) {
$http.post("/reports/api/g3swmf/report", $scope.g3sWmf ).success(function(data){
readOptions.success(data);
})
}