uniapp及vue中使用Es6中的map

1.定义(data中return)

answerSheetMap:[],//答题卡

2.在生命周期上定义

this.answerSheetMap = new Map();

3.对后端返回数据进行处理(功能将题型根据名字不同存放)

showCardModal: function(e) {
				
				this.modalCard = e.currentTarget.dataset.target
				this.answerSheetMap.clear();
				for(let i = 0;i < this.subjectList.length;i ++){
					this.subjectList[i].count = i+1;
					if(this.answerSheetMap.get(this.subjectList[i].showType) == undefined){
						this.answerSheetMap.set(this.subjectList[i].showType,[]);
						this.answerSheetMap.get(this.subjectList[i].showType).push(this.subjectList[i])
					}else{
						this.answerSheetMap.get(this.subjectList[i].showType).push(this.subjectList[i])
					}
					
				}
				this.keys = this.answerSheetMap.keys();
				this.values = this.answerSheetMap.values();
				this.entries = this.answerSheetMap.entries();
				for(let [key, value] of this.answerSheetMap){
					console.log(key, value)
				}
				console.log('map6666',this.answerSheetMap,this.keys,this.values,this.entries)
			},

在这里插入图片描述
4.如何像数组一样(v-for)在template中展示

<view v-for="(key,value) of answerSheetMap" style="width: 100%;">
				<view class="answerCardname" style="width: 100%;text-align: left;height: 10vw;line-height: 10vw;font-weight: 700;">
									{{key[0]}}
					</view>
			<view style="display: flex;">
				<view style="width: 15vw;text-align: center; " class="margin-tb-sm text-center" v-for="(subject,index) in answerSheetMap.get(key[0])" :key="index">
									
						<button class="cu-btn round" :class="subject.answer == null? 'notAnswer':'yesAnswer'"  @click="AppointedSubject(subject.count)" >{{index+1}}</button>
				</view>
			</view>
	</view>

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值