TypeError:无法读取未定义的属性nodeName

时间:2015-10-15 08:29:26

标签: javascript node.js

我正在使用Elasticsearch和Node进行后端应用程序。 我试图获得弹性响应。但是这个错误发生了。

                uniqueid = (source[i]._source.uniqueid ? source[i]._source.uniqu
eid : source
                                     ^
TypeError: Cannot read property '_source' of undefined

源代码:

var createArray = function(source, callback){
    this.source = source;
    var len = source.length;
    var eventDetails = [];
    var uniqueid;
    var i;
    for(i=0; i <= len ;i++)
    {

        uniqueid = (source[i]._source.uniqueid ? source[i]._source.uniqueid : source[i]._source.uniqueid1 );
        /....../
        eventDetails.push(uniqueid);
    }
    callback(eventDetails);
};

源数组是这样的:

[
      {
        "_index": "tests",
        "_type": "Hangup",
        "_id": "1",
        "_score": 1,
        "_source": {
          "event": "Hangup",
          "privilege": "call,all",
          "channel": "SIP/102-000001aa<ZOMBIE>",
          "uniqueid": "14448293848.505",
          "calleridnum": "102",
          "calleridname": "Backup Reception",
          "connectedlinenum": "122",
          "connectedlinename": "someone eles",
          "accountcode": "",
          "cause": "16",
          "cause-txt": "Normal Clearing",
          "created": 1444829486490,
          "cnt": 22
        }
      },
      {
        "_index": "tests",
        "_type": "Hangup",
        "_id": "2",
        "_score": 1,
        "_source": {
          "event": "Hangup",
          "privilege": "call,all",
          "channel": "SIP/121-000001b0",
          "uniqueid": "14448932858.518",
          "calleridnum": "121",
          "calleridname": "someone",
          "connectedlinenum": "<unknown>",
          "connectedlinename": "<unknown>",
          "accountcode": "",
          "cause": "16",
          "cause-txt": "Normal Clearing",
          "created": 1444892559309,
          "cnt": 26
        }
      }
    ]

我尝试这个单行代码,一切正常 就是这样:

source[0]._source.uniqueid

0 个答案:

没有答案