代码如下:
res.forEach(e=>{
console.log(e.name) //这个显示正常
e.children.forEach(item=>{
console.log(item.name) //这个提示错误 “Uncaught (in promise) TypeError: e.children.forEach is not a function”
})
})
e的数据如图:
补充:
感谢回复,先用for in 处理下了,
但是还有几个疑问希望能解答下
问题1:
我打印res
console.log(typeof res)
出来的也是对象
怎么res可以forEach呢?
问题2:
原始数据php代码如下:
$routes =[
[
'path'=>'/',
'component'=>'Layout',
'name'=>'首页',
'menu'=>"true",
'children'=> [
'path'=>'/Dashboard',
'component'=>'/views/Dashboard',
'name'=>'仪表盘',
'menu'=>"true"
],
],
];
在vue中axios,get获取到了这个php输出的JSON
需要怎么处理,也可以把res里的每个children也能forEach呢?
e.children是个对象,不能用forEach遍历