Javascript TypeError:无法读取未定义的属性nodeName
我正在为后端应用程序使用Elasticsearch和Node。 我试图得到弹性反应,但这个错误发生了Javascript TypeError:无法读取未定义的属性nodeName,javascript,node.js,Javascript,Node.js,我正在为后端应用程序使用Elasticsearch和Node。 我试图得到弹性反应,但这个错误发生了 uniqueid = (source[i]._source.uniqueid ? source[i]._source.uniqu eid : source ^ TypeError: Cannot read property '_source' of undefined 源代码: var c
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);
};
我使用了越界?你的循环应该是iYes.:为什么不能使用此eventDetails[source[i]。\u source.cnt].pushuniqueid;正如t.niese指出的问题是,如果源数组有5个元素,那么它们是源[0]到源[4]。如果你用的是很短的答案,按照他说的去做,然后改变我的想法
[
{
"_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