微信小程序for循环里面添加input事件
1,在微信小程序for循环里面添加input事件,并把input输入值添加到列表里面
2.wxml
<view class="item" wx:for="{
{list}}" wx:for-item="vo" wx:key="index" data-
item="{
{vo}}">
<view class="col">{
{vo.name}}</view>
<view class="col2">{
{vo.task_startTime}}</view>
<view class="col2">{
{vo.task_endTime}}</view>
<view class="col">{
{vo.work_hours}}</view>
<view class="col stepper" >
<input data-id="{
{index}}" value="{
{vo.money}}" bindfocus="bindFocus" bindinput="bindKeyInput"></input>
</view>
</view>
js
data:{
list:[
{
name:'嘻嘻',
task_startTime:'2020/12/03 12:56',
task_endTime:'2020/12/03 15:56',
work_hours:'3.0',
money:0
}
],
inputValue: '',
focusId: ''
},
bindFocus: function (event) {
let id = event.currentTarget.dataset.id
console.log(id)
this.setData({
focusId: id
})
},
bindKeyInput: function (event) {
let that = this;
let value = Number(event.detail.value)
let id = event.currentTarget.dataset.id
var up = 'list[' + id + '].money';
this.setData({
[up]:value
})
console.log(that.data.focusId)
console.log(that.data.list)
},
还没有评论,来说两句吧...