我正在尝试在nodejs中使用变量。无论我尝试什么,它都会给我错误。 如何在此字符串中使用变量
let txt= 'some unknown texts'
"MATCH (productName) AGAINST ('txt')"
这里我需要替换txt。
注意:我无法使用``
编辑 这是我正在使用的查询
await Product.query().whereRaw("MATCH (productName) AGAINST ('txt')").select('productName')
谢谢。
最佳答案
在 ES6 中,您需要执行以下操作才能在字符串中使用 var
`MATCH (productName) AGAINST ${txt}`
如果你不能使用``
只需采用字符串连接的旧方法即可,
"MATCH (productName) AGAINST '" +txt + "'"
关于Javascript变量内引号(双内单引号),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50997423/