我有一个剑道电网,目前我们创建作为数据源:我们可以在Kendo Grid中读取复杂对象吗?
var gridDataSource = new kendo.data.DataSource({
transport: {
read: {
url: '@Url.Action("GetData", "Report")',
dataType: "json"
}
},
group: [
{ field: "Name" },
],
pageSize: 20,
serverPaging: false,
serverFiltering: false,
sort: { field: "Date", dir: "desc" },
schema: {
......
model: {
fields: {
Date: { type: "date" },
Name: { type: "string" },
Version: { type: "string" },
Count: { type: "number" }
}
}
}
});
它调用的GetData报告中获取数据。返回的数据是具有日期,名称,版本和计数的类ReportRow的列表。
在后端,这个报告将保存在DocumentDB,该做的GetData是:
public async Task<ContentResult> GetData()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = string.Empty;
try
{
// this json has the time stamp attribute and Rows (array, which is what the grid shows)
json = await _reportRepository.FindDocumentByQueryStringAsync(".....");
if (!string.IsNullOrEmpty(json))
{
// convert the json
....
List<ReportRow> rowList = new List<ReportRow>();
...
{
// parse the json, get results
rowList = reportResults.Rows;
}
...
string ojson = serializer.Serialize(rowList);
return this.Content(ojson, "application/json");
}
}
catch (Exception ex)
{
_log.LogError("...");
}
return this.Content(json, "application/json");
}
当我们表现出的报告,我们要显示在报表的时间戳记。我的想法是:我们可以在_reportRepository中创建另一个方法来返回报告时间戳,在控制器中调用它并传递给视图。但同事问道:既然我们在GetData中得到了时间戳,是否有一种方法可以使用它,这样我们就不必更改_reportRepository并再次打电话了?
所以,我的问题是:如果在GetData中,我们直接将json传递给Kendo网格,我应该如何在gridDataSource中进行更改?我们如何在模式中定义模型?或者,剑道的模型必须是简单的类型,即字符串,数字,日期......?如果我们能做到这一点,我应该在阅读事件中改变什么?
我搜索了,但找不到答案。
感谢
让我看看我是否明白你的意思:你想获得并使用'read'请求中的信息作为其他目的?如果是的话,我知道你是如何做到的。 – DontVoteMeDown
可否请您详细说明您的场景或提供一些截图以了解需求? –