我正在构建 Loopback 的自定义远程方法。当我进行查询并尝试将关系转发到自己的函数时,其中 forEach.关系列表导致错误 relations.forEach 不是函数
示例:
return Api.find({include: ['relations']}).then(result => {
return myFunction(result.relations)
})
myFunction(relations) {relations.forEach(obj => {console.log(obj)})};
如何将 List 对象转换为 JavaScript 数组。 toJSON() 不适用于列表对象
最佳答案
您是否尝试过直接对结果进行 JSON 转换?喜欢:
return Api.find({include: ['relations']}).then(result => {
result = result.toJSON(); //add this line
return myFunction(result.relations)
})
myFunction(relations) {relations.forEach(obj => {console.log(obj)})};
关于javascript - 环回远程方法关系列表到 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54434452/