小程序中監聽textarea或者input輸入的值動態改變data中數組的對象的值


Page({
  data: {
    todoLists:[
      {
        detail:"",
        date:"",
        location:"",
        priority:"",
        remark:"",
        dateStatus:false,
        locationStatus:false,
        dateRepeat:false,
        completeStatus: false,
        currentInput:"",
      },
      {
        detail: "",
        date: "",
        location: "",
        priority: "",
        remark: "",
        dateStatus: false,
        locationStatus: false,
        dateRepeat: false,
        completeStatus: false,
        currentInput:"",
      }
    ],
  },
  getInput:function(e){
    let index = e.currentTarget.dataset.index;
    let currentInput = `todoLists[${index}].currentInput`;
    this.data.todoLists[index].currentInput = e.detail.value;
    this.setData({
      todoLists: this.data.todoLists
    })
    console.log(this.data.todoLists[index].currentInput) // 可以實時改變
  }
})
<textarea class="weui-textarea {{ item.completeStatus && item.completeStatus === true ? 'text-transparent' : '' }}" placeholder="請輸入文本" bindinput="getInput" maxlength="1000" data-index="{{index}}" value="{{item.currentInput}}" auto-height auto-focus="true" />

小程序中監聽textarea或者input輸入的值動態改變data中數組的對象的值,不能通過setData設置數組對應索引的對象的值來改變,改變之后,能檢測到改變,但是值為空。先通過賦值改變其中數組中的對象的值,然后重新設置數組。

參考鏈接:https://blog.csdn.net/chou_out_man/article/details/75575100


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM