当前位置:   article > 正文

数据双向绑定Two-way binding does not support complex data paths currently. This two-way binding is ignored

two-way binding does not support complex data paths currently. this two-way

项目场景:

后端返回数据,小程序用wx:for循环数据,实现双向绑定提示报Two-way binding does not support complex data paths currently. This two-way binding is ignored


问题描述

model:value不能实现双向绑定,

wxml:

  1. <view>
  2.   <view  wx:for="{{listData}}"  wx:key="true" wx:for-index="i">
  3.     <view>
  4.       <view>时间:</view>
  5.       <input type="text" model:value="{{item.applyTime}}" data-id="{{i}}" placeholder="请输入时间" />
  6.     </view>
  7.     <view>
  8.       <view>机构:</view> 
  9.       <input type="text" model:value="{{item.detectionCompany}}" data-id="{{i}}" placeholder="请输入机构" />
  10.     </view>
  11.   </view>
  12. </view>

解决方案:

添加bindinput方法,实现双向绑定

wxml:

  1. <view>
  2.   <view  wx:for="{{listData}}"  wx:key="true" wx:for-index="i">
  3.     <view>
  4.       <view>时间:</view>
  5.       <input type="text" model:value="{{item.applyTime}}" data-id="{{i}}" placeholder="请输入时间" bindinput="inputApplyTime"/>
  6.     </view>
  7.     <view>
  8.       <view>机构:</view> 
  9.       <input type="text" model:value="{{item.detectionCompany}}" data-id="{{i}}" placeholder="请输入机构" bindinput="inputDetectionCompany"/>
  10.     </view>
  11.   </view>
  12. </view>

js:

  1.  data: {
  2.     listData:[],
  3. }
  4.  //双向绑定数据
  5.   inputApplyTime:function(e){
  6.     var applyTime = e.detail.value
  7.     var i = e.currentTarget.dataset.id
  8.     this.data.listData[i].applyTime = applyTime
  9.     this.setData({
  10.       listDatathis.data.listData
  11.     })
  12.   },
  13.   inputDetectionCompany:function(e){
  14.     var detectionCompany = e.detail.value
  15.     var i = e.currentTarget.dataset.id
  16.     this.data.listData[i].detectionCompany = detectionCompany
  17.     this.setData({
  18.       listDatathis.data.listData
  19.     })
  20.   },

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/94228
推荐阅读
相关标签
  

闽ICP备14008679号