uniapp前端循环数组取值方法

两种方法

一 不懂得找我下哈


<!-- 遍历数组 -->
			<view class="itemList">
				<view class="item acea-row row-between-wrapper" v-for="(item, indexw) in hnUserlist"
					:key="indexw">
					<view class="namele">{{ item.allname }}</view>
					<view class="listn acea-row row-middle">
						<view class="itemn" :class=" item.indexOld == indexn ?'on' : '' " 
							v-for="(itemn, indexn) in item.detailValue" @click="tapAttr(indexw, indexn,{[item.name]:itemn.value})" :key="indexn" >
							{{ itemn.name}}
						</view>
					</view>
				</view>
			</view>

方法
hnUserlist:[
					{
						detailValue: [{
							name: '男',
							value: 0
						}, {
							name: '女',
							value: 1
						}],
						indexOld: 0,
						allname: "性别",
						name: 'sex1'
					},
					{
						detailValue: [{
							name: '社区居民',
							value: 0
						}, {
							name: '非社区',
							value: 1
						}],
						indexOld: 1,
						allname: "常驻类型",
						name: "reside1",
						}】

methods: {
			bindDateChange: function(res) {
			             this.birthday1 = res.target.value
						console.log(res.detail.value)
			        },
			        getDate(type) {
			            const date = new Date();
			            let year = date.getFullYear();
			            let month = date.getMonth() + 1;
			            let day = date.getDate();
									
			            if (type === 'start') {
			                year = year - 60;
			            } else if (type === 'end') {
			                year = year + 2;
			            }
			            month = month > 9 ? month : '0' + month;;
			            day = day > 9 ? day : '0' + day;
			            return `${year}-${month}-${day}`;
			        },
			
			initHnUser: function(res) {
				let that = this;
			},	
			tapAttr: function(indexw, indexn,value) {
			//注释的是两种方法
			/* 	this.clickArr[indexw] ? this.clickArr.splice(indexw, 0,{indexw: indexw, indexn: indexn,value: value}) : this.clickArr.push({indexw: indexw, indexn: indexn, value: value}) */
				this.hnUserlist[indexw].indexOld = indexn;		
				if (indexw == 0) {
				     this.addressData.sex1 = indexn
				    } else if (indexw == 1) {
				     this.addressData.reside1 = indexn
				    } else if (indexw == 2) {
				     this.addressData.nation1 = indexn
				    } else if (indexw == 3) {
				     this.addressData.bloodYype1 = indexn
				    } else if (indexw == 4) {
				     this.addressData.standardCulture1 = indexn
				    } else if (indexw == 5) {
				     this.addressData.profession1 = indexn
				    } else if (indexw == 6) {
				     this.addressData.marriageStatus1 = indexn
				    } else if (indexw == 7) {
				     this.addressData.healthProducts1 = indexn
				    } else if (indexw == 8) {
				     this.addressData.takeExercise1 = indexn
				    } else if (indexw == 9) {
				     this.addressData.communityActivity1 = indexn
				    } else if (indexw == 10) {
				     this.addressData.healthSurvey1 = indexn
				    }
				/* let that = this;	 */
				console.log(this.clickArr);
				console.log("indexw", indexw);
				console.log("indexn", indexn);
				/* this.sex1 = this.clickArr.sex.value; */
				/* 	this.sex1 = this.hnUserlist[indexw].indexOld = indexn;
			
					 this.reside1 = this.hnUserlist[indexw].indexOld = indexn; */

						 /* this.nation1 = this.hnUserlist[indexw].indexOld= indexn;
						    this.bloodYype1 = this.hnUserlist[indexw].indexOld= indexn;
							 this.standardCulture1 = this.hnUserlist[indexw].indexOld= indexn;
							  this.profession1 = this.hnUserlist[indexw].indexOld= indexn;
							   this.marriageStatus1 = this.hnUserlist[indexw].indexOld= indexn;
							    this.healthProducts1 = this.hnUserlist[indexw].indexOld= indexn;
								 this.takeExercise1 = this.hnUserlist[indexw].indexOld= indexn;
								  this.communityActivity1 = this.hnUserlist[indexw].indexOld= indexn;
								   this.healthSurvey1 = this.hnUserlist[indexw].indexOld= indexn;		 */					
			},
			//提交
			submit(e){
			//这里是转义的意思
			/* 	this.clickArr.reduce((pre,cur) =>{
					return Object.assign(pre,cur)
				},{})
				console.log({...this.clickArr.map(v => v.value)})
				console.log(this.clickArr.reduce((pre,cur) =>{
					return Object.assign(pre,cur)
				},{})) */
				  /* var data = e.detail.value */
				 let data = this.addressData	
				 console.log('this.addressData', this.addressData)
							console.log(this.data)						
				postUsermessage({
					
					sex: data.sex1,
					reside: data.reside1,
				   realName: this.addressData.realName1,
					mobile: this.addressData.mobile1,
					examinationTimes: this.addressData.examinationTimes1,
					subHealthRemark: this.addressData.subHealthRemark1,
					xryTimes: this.addressData.xryTimes1,
					xryExperience: this.addressData.xryExperience1,
					xqjTimes: this.addressData.xqjTimes1,
					xqjExperience: this.addressData.xqjExperience1,
					fqsTimes: this.addressData.fqsTimes1,
					fqsExperience: this.addressData.fqsExperience1,
					birthday: this.currentDate,
										
					nation: data.nation1,
					bloodYype: data.bloodYype1,
					standardCulture: data.standardCulture1,
					profession: data.profession1,
					marriageStatus: data.marriageStatus1,
					healthProducts: data.healthProducts1,
					takeExercise: data.takeExercise1,
					communityActivity: data.communityActivity1,
					healthSurvey: data.healthSurvey1,
				  })
				  .then((res) => {
				    handleOrderPayResults.call(this, res.data, "create", this.active);
				  })

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值