Add input event in the for loop of WeChat applet

1. Add an input event in the for loop of the WeChat applet, and add the input value to the list

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)
   
  },

Guess you like

Origin blog.csdn.net/asteriaV/article/details/110793708