我有一个 jquery 库可以处理这种形式的数据
data = [{
label: 'IVR',
data: dIvr
}, {
label: 'Agents',
data: dAgents
}, {
label: 'Abandoned',
data: dAbandoned
}, {
label: 'Cancelled',
data: dCancelled
}];
我需要使用它,所以我构建了这个函数:
$.getJSON('url',
{ fromDate: "01-01-2014", toDate: "09-04-2014" })
.done(function (result) {
var data = [];
$.each(result, function (index, value) {
var obj = {};
obj.label = value.Campaign;
if (value.Count == 0) {
obj.data = 0;
} else {
obj.data = value.SL / value.Count;
}
data.push(obj);
})
console.log(data)
我使用 console.log
打印数据,结果是这样的:
这两种数据格式一样吗?我问是因为我从图书馆得到异常(exception)。当我手动制作数据时我没有得到这些异常,但是当我使用上面的函数时,我得到了异常
谁需要异常(exception)
Cannot read property '0' of undefined
in the jquery.flot.orderBars.js
like 79
最佳答案
给定异常
Cannot read property '0' of undefined in the jquery.flot.orderBars.js line 79
异常发生的行
minMaxValues[0] =series[i].data[0][AxeIdx];
series[i]
未定义,或 data[0]
未定义。 data[0]
很可能是未定义的,因为您传递的对象数组中的 data
包含数字而不是数组。
关于javascript - jquery 这两种格式相同吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23064074/