uniapp 用forEach循环遍历数组

<!-- 返回的数据:
res =[{
    
    
	"parentId": null,
	"orderNum": null,
	"categoryId": 56,
	"categoryName": "分类一",
	"sort": 6
},
{
    
    
	"parentId": 1,
	"orderNum": null,
	"categoryId": 57,
	"categoryName": "分类二",
	"sort": 6
}] -->

let parentIdList= res
parentIdList.forEach((item,index)=>{
    
    
	if(item.parentId == null){
    
    
		// 此处获得的id为56
		this.categoryId = item.categoryId
	}
});

猜你喜欢

转载自blog.csdn.net/maoge_666/article/details/130151824
今日推荐