el-select回显多选数据(下拉里有一级数据,也有二级数据)

 具体的数据还请各位根据自己项目而定
 

实现效果:

1.多选为一级时回显:

2.多选为二级时回显:

 

代码: 

        // 回显服务类别
		showInsured () {
			console.log(this.form.serviceType) // 这个是点击修改时获取到的多选值
			let tempInsured = this.form.serviceType ? this.form.serviceType.split(',') : []
			let insured = []
			for (let i = 0;i < tempInsured.length;i++) {
				let arr = [tempInsured[i]]
				console.log(tempInsured[i], 'ppp')
				let temp = this.findParent(tempInsured[i])
				if (temp != 0) {
					arr.unshift(this.findParent(tempInsured[i]))
				}
				console.log(arr, '000')
				insured.push(arr)
			}
			this.form.serviceType = insured
			console.log(this.form.serviceType)
		},


        // 查找父节点
		findParent (childeNode) {
			console.log(childeNode)
			console.log(this.productTypeList)  // 当前下拉数组
			let parentNode = 0
			for (let i = 0;i < this.productTypeList.length;i++) {
				if (this.productTypeList[i].children) {
					if (this.productTypeList[i].value == childeNode) {
						return 0 // 说明当前节点已为父节点
					} else {
						console.log(this.productTypeList[i])
						let index = this.productTypeList[i].children.findIndex(item => item.value == childeNode)
						console.log(index)
						if (index != -1) {
							parentNode = this.productTypeList[i].value
							break
						}
					}
				}

			}
			return parentNode
		},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值