数组遍历组成新数组,用数组方法map,

const _this = this
				var duoxuanshuzu = []
				_this.listright.map((item, index) => {
					duoxuanshuzu.push(
						//重新加属性建数组,符合组件的要求
						Object.assign({
							id: index
						}, {
							tag: item
						})
					)
				})
				console.log(duoxuanshuzu)

 

数组过滤filter,删除数组中重复的某一项findIndex,不重复的就push到新数组中

change(item) {
				// console.log(item)
				this.id = item.id

				if (this.ids.includes(this.id)) {
					// id数组filter方法
					this.ids = this.ids.filter(item => {
						return item != this.id
					})
					console.log('id=>', this.id)
					// choice数组,重复点击删除此项 
					var index0 = this.choice.findIndex(item => {
						if (item.id == this.id) {
							return true
						}
					})
					this.choice.splice(index0, 1)
				} else {
					
						this.ids.push(this.id);
						this.choice.push(item.tag);
					
				}
}

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐