< view class = 'item-immune' wx:for = "{{ array_immune }}" wx:key = "immune" > < view > < text >组织部位:</ text > < input placeholder = '请输入部位' name = "sPart_{{ item }}" ></ input > </ view > </view |
项目需要动态添加多条记录,提交需要对每条值进行校验,循环获取值无效,js如下,知道是因为input 拼接不对,大家如何去实现的
for ( var step = 1; step <= that.data.array_immune.length; step++) { var sPart = event.detail.value.sPart_+step; console.log(sPart) } |
结果是NaN
楼主的意思是点击提交按钮循环获取input的值,4楼你是想实现什么功能呢?另外data-index="{{index}}", index是指array_mmune的下标,data{}里面不需要index:[1,2,3]。
比如:data:{
array_immune:[
{ id: 1 },
{ id: 2 },
{ id: 3 }
]
}
在onLoad的时候可以for循环先把array_immune每一项都加上val=’ ';
array_immune:[
{ id: 1 ,val:’’},
{ id: 2 ,val:’’},
{ id: 3 ,val:’’}
]
data{array: [‘请选择’, ‘品牌’, ‘类别’, ‘中文名’, ‘英文名’],
index: [0,1,2]
}
<picker mode=“selector” value="{{index}}" range="{{array}}">
<view class=“picker”>
{{array[index]}}
</view>
</picker>
当我选择了“”中文名“”之后,我怎么获取到他,怎么把他赋值到页面,就跟下拉框选中一样让它固定在我选择的地方
< picker bindchange = "bindPickerChange" value = "{{index}}" range = "{{array}}" > < view class = "picker" > 当前选择:{{array[index]}} </ view > </ picker > |
data: { array: [ '请选择' , '品牌' , '类别' , '中文名' , '英文名' ] }, bindPickerChange: function (e) { this .setData({ index: e.detail.value }) }, |
<view class=‘item-immune’ wx:for="{{ array_immune }}" wx:key=“immune”>
<view>
<text>组织部位:</text>
<input placeholder=‘请输入部位’ name=“sPart” bindinput=‘ipt’ data-index="{{index}}"></input>
</view>
</view>
ipt:function(e){
let index = e.currentTarget.dataset.index;
let array_immune = this.data.array_immune;
let len = array_immune.length;
array_immune[index].val = e.detail.value;
this.setData({
array_immune: array_immune
})
},
看看可以不?