JS 获取筛选过的list item的某些属性

前言

接口是一次性返回所有的分类的,所以得要前端这边自己处理数据

最终效果

3列联动选择

 

uniapp 的select 选择器,固定死字段名了,所以我们 还需要给接口返回的字段重新命名

实现

活用list 的map(),filter(),方法

<u-select v-model="isPlatforationSelectShow" mode="mutil-column-auto" :list="platformCategorysList" @confirm="confirm" title="平台分类">
		</u-select>
isPlatforationSelectShow: false, // data那里定义变量
platformCategorysList: [],

// 请求接口以后返回的操作
let dataList = res.data
this.platformCategorysList = []
dataList.forEach((item,index) => {
	if(item.level === 0) {
		let myItem = {}
		myItem.value = item.categoryId
		myItem.categoryId = item.categoryId
		myItem.label = item.name
		myItem.level = item.level
		this.platformCategorysList.push(myItem)
	}
})
this.platformCategorysList.forEach((item0,index0) => {
	// this.platformCategorysList[index1].children = dataList.filter(item => item.parentId === item1.categoryId)
	let filterList2 = dataList.filter(item1 => item1.parentId === item0.categoryId)
	this.platformCategorysList[index0].children = filterList2.map((item2,
index2) => {
		if (item2.parentId === item0.categoryId) {
			let filterList3 = dataList.filter(item3 => item3.parentId === item2.categoryId)
				let mapList3 = []
				mapList3 = filterList3.map((item33,index33) => {
					return {
						'value': item33.id,
						'categoryId': item33.categoryId,
						'label': item33.name,
						'level': item33.level
					}
				})
				return {
					'value': item2.id,
					'categoryId': item2.categoryId,
					'label': item2.name,
					'level': item2.level,
					'children': mapList3
				}
		}
	})
})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值