我对JavaScript和Mysql很陌生。 MySQL查询(我已经在JS的服务器端代码中运行过)以这种形式返回行
即console.log(rows)给出:-
[ RowDataPacket {
id: 7080,
post_author: 134,
post_title: '99 Varieties Dosa, Indira Nagar',
post_content: 'There',
link: '99-varieties-dosa-indira-nagar',
seo_keywords: null,
seo_desc: null,
seo_title: null,
best_for: 'Dosas',
special_info: '',
also_serves: 'Dosas',
'close-timing': '',
address: '56, 9th A Main Road',
direction_landmarks: 'Located in Indira Nagar',
seating: 'Unavailable',
longitude: '77.64097630979995',
latitude: '12.9777060556',
phone_no: ' ',
image_url: null,
location: 'Indira Nagar',
cuisine: 'South Indian Tiffin',
categories: 'Local Food',
Tags: 'Mysore Masala Dosa' }]
[ RowDataPacket {...}]
[ RowDataPacket {...}]
[ RowDataPacket {...}]
[ RowDataPacket {...}]
如何访问RowDataPacket
对象的位置键?
我尝试了rows[i].location
,rows[i]["location"]
,rows.location
,rows[i].RowDataPacket.location
等。
答案 0 :(得分:0)
在执行console.log(rows);时您将以JSON数组的形式获取数据,可以使用以下代码段进行访问:
$.each(rows, function(index, data){
// check your index & data details like below & perform other tasks
console.log('INDEX=', index);
consoel.log('DATA=', data); // Here data will be an object
// to access individual key data like location, you can try below code
console.log('LOCATION=', data.location);
});
有关更多参考,您可以通过链接:https://api.jquery.com/each/