我正在尝试使用动态计算的数据填充 kendoUI 网格并将其推送到变量中。我的网格是在 div 标签中定义的,但是当调用该函数时,只显示网格(带有列名),没有数据。我认为我缺少一个导致此问题的一小步。这是我的问题的图像:
任何帮助将不胜感激!
此函数中生成的数据:
function calcROI(mpy) {
var data = [];
var g_items = new Array();
var payment = 0;
var d = new Date(_startDate);
var inc = mpy / 12.00;
var time = 0.00;
var limit = years;
for (var i = 0; time < years; i++, time += inc) {
var item = new Object();
pay = i;
var day = new Date(d.setMonth(d.getMonth() + mpy));
var ac = +annualCost + +(annualCost * time);
var cost = ac + +oneTimeCost;
var ben = +benefits + +(+benefits * time);
var dif = ben - cost;
var roi = (ben - cost) / cost * 100;
data.push({
payment: pay,
date: day,
aCost: ac,
cost: cost,
benefits: ben,
difference: dif,
roi: roi,
});
}
return data;
}
正在从 make grid 函数内部调用该函数
function makeGrid2(mpy) {
var ds = new kendo.data.DataSource({ data: calcROI(mpy) })
ds.read();
$("#grid").kendoGrid({
dataSource: ds,
height: 550,
columns: [{
field: "payment",
title: "Payment",
}, {
field: "date",
title: "Date"
}, {
field: "aCost",
title: "Accumulated Costs"
},{
field: "cost",
title: "Total Costs"
},{
field: "benefits",
title: "Benefits"
},{
field: "difference",
title: "Difference"
},{
field: "roi",
title: "ROI%"
}]
});
}
在VS2013中,当我输出我的数据源变量时,我得到了这个
{
"options": {
"data": [
{
"payment": 0,
"date": "2015-07-26T04:00:00.000Z",
"aCost": 123,
"cost": 246,
"benefits": 123,
"difference": -123,
"roi": -50
},
{
"payment": 1,
"date": "2016-07-26T04:00:00.000Z",
"aCost": 246,
"cost": 369,
"benefits": 246,
"difference": -123,
"roi": -33.33333333333333
}
],
"schema": {},
"serverSorting": false,
"serverPaging": false,
"serverFiltering": false,
"serverGrouping": false,
"serverAggregates": false,
"batch": false
},
"_map": {},
"_prefetch": {},
"_data": [
{
"payment": 0,
"date": "2015-07-26T04:00:00.000Z",
"aCost": 123,
"cost": 246,
"benefits": 123,
"difference": -123,
"roi": -50
},
{
"payment": 1,
"date": "2016-07-26T04:00:00.000Z",
"aCost": 246,
"cost": 369,
"benefits": 246,
"difference": -123,
"roi": -33.33333333333333
}
],
"_pristineData": [
{
"payment": 0,
"date": "2015-07-26T04:00:00.000Z",
"aCost": 123,
"cost": 246,
"benefits": 123,
"difference": -123,
"roi": -50
},
{
"payment": 1,
"date": "2016-07-26T04:00:00.000Z",
"aCost": 246,
"cost": 369,
"benefits": 246,
"difference": -123,
"roi": -33.33333333333333
}
],
"_ranges": [
{
"start": 0,
"end": 2,
"data": [
{
"payment": 0,
"date": "2015-07-26T04:00:00.000Z",
"aCost": 123,
"cost": 246,
"benefits": 123,
"difference": -123,
"roi": -50
},
{
"payment": 1,
"date": "2016-07-26T04:00:00.000Z",
"aCost": 246,
"cost": 369,
"benefits": 246,
"difference": -123,
"roi": -33.33333333333333
}
]
}
],
"_view": [
{
"payment": 0,
"date": "2015-07-26T04:00:00.000Z",
"aCost": 123,
"cost": 246,
"benefits": 123,
"difference": -123,
"roi": -50
},
{
"payment": 1,
"date": "2016-07-26T04:00:00.000Z",
"aCost": 246,
"cost": 369,
"benefits": 246,
"difference": -123,
"roi": -33.33333333333333
}
],
"_pristineTotal": 2,
"_destroyed": [],
"_group": [],
"_total": 2,
"_events": {},
"transport": {
"data": [
{
"payment": 0,
"date": "2015-07-26T04:00:00.000Z",
"aCost": 123,
"cost": 246,
"benefits": 123,
"difference": -123,
"roi": -50
},
{
"payment": 1,
"date": "2016-07-26T04:00:00.000Z",
"aCost": 246,
"cost": 369,
"benefits": 246,
"difference": -123,
"roi": -33.33333333333333
}
]
},
"reader": {},
"_requestInProgress": false,
"_aggregateResult": {}
}