我使用node.js作为服务器语言,使用Mysql作为数据库,因此我正在运行查询并从数据库中获取数据,但是以这种格式显示
[ BinaryRow { name: 'Dheeraj',amount: '77.0000' },BinaryRow { name: 'Raju',amount: '255.0000' } ]
我想要的是
['Dheeraj',77.0000],['Raju',66255.000030],
这是我在后端(node.js)中正在做的事情:
我的模特:
static getchartData(phoneNo,userType) {
let sql = 'select businessname as name,sum(billamt) amount from cashbackdispdets where consphoneno =' + phoneNo + ' group by businessid order by tstime desc limit 10'
return db.execute(sql,[phoneNo]);
我的控制器:
exports.getcolumnChart = function(req,res) {
const phoneNo = req.body.userId
const userType = req.body.userType
console.log(phoneNo)
dashboardmodule.getchartData(phoneNo,userType)
.then(([rows]) => {
if (rows.length > 0) {
console.log(rows)
return res.json(rows)
} else {
console.log("error")
return res.status(404).json({ error: 'Phone No. already taken' })
}
})
.catch((error) => {
console.log(error)
return res.status(404).json({ error: 'Something went wrong !!' })
})
}
我正在将这些数据发送到Ui
,当我在UI
上接收到它时,它是数组内对象的形式,这不是我想要的必需数据类型
axios().post('/api/v1/Dashboard/DashboardColumnChart',this.form)
.then(res=>{
console.log(res.data)
debugger
this.chartData= res.data
})
我不知道该如何使用后端或前端以及如何操作