本帖最后由 plutosherry 于 2020-6-30 00:29 编辑
const list = [
{
alias: ['晚安'],
proxy: '/endpoint/miai/ha/goodnight'
},
{
alias: ['室内空气指数'],
proxy: '/endpoint/miai/ha/airquality'
},
{
alias: ['切灯'],
proxy: '/endpoint/miai/ha/switchlight'
},
{
alias: ['打开客厅灯'],
proxy: '/endpoint/miai/ha/livingroom_light1'
},
{
alias: ['关闭客厅灯'],
proxy: '/endpoint/miai/ha/livingroom_light1'
}
]
let queries = []
msg.payload.cmd && queries.push(msg.payload.cmd)
try {
//queries = JSON.parse(msg.payload.res).response.answer[0].intention.query;
queries = '切灯';
} catch (e) {
}
msg.queries = queries
msg.list = list
msg.matched = !!list.filter((item, index) => {
matched = ~item.alias.indexOf(queries).length
matched && (msg.matched_index = index)
return matched
}).length
return msg;
哪位大神能解释一下 为何 当 queries = '切灯' 的时候,msg.matched_index = 5 而不是 = 2?
最终导致list中的index索引错乱
|