【发布时间】:2018-11-29 22:43:02
【问题描述】:
我有一个 node.js mysql 查询:
connection.query("SELECT id AS id, name AS label, status AS status from table;", function(err, rows) {
...
});
我得到的结果是这样的:
console.log(getBody)
[ { id: '1',
label: 'Name 01',
status: 'ACTIVE' },
{ id: '2',
label: 'Name 02',
status: 'INACTIVE' },
{ id: '3',
label: 'Name 03',
status: 'ACTIVE' },
{ id: '4',
label: 'Name 04',
status: 'ACTIVE' }];
为了进一步计算结果......我需要一个额外的参数“类型”,在数组中具有固定值。所以结果应该是这样的:
[ { id: '1',
label: 'Name 01',
status: 'ACTIVE',
type: 'ABC' },
{ id: '2',
label: 'Name 02',
status: 'INACTIVE',
type: 'ABC' },
{ id: '3',
label: 'Name 03',
status: 'ACTIVE',
type: 'ABC' },
{ id: '4',
label: 'Name 04',
status: 'ACTIVE',
type: 'ABC' }];
最快/最好的方法是什么?循环数组?它应该是什么样子?
【问题讨论】:
标签: javascript mysql sql node.js