jquery这两种格式是一样的吗?

时间:2014-04-14 15:28:57

标签: javascript jquery

我有一个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打印数据,结果如下: enter image description here

这两种数据格式是否相同?我问,因为我从图书馆得到例外。我手工编写数据时没有得到这些异常,但是当我使用上面的函数时,我得到了异常

谁需要例外

Cannot read property '0' of undefined中的jquery.flot.orderBars.js,如79

1 个答案:

答案 0 :(得分:3)

鉴于异常

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包含数字而不是数组。