收藏
回答

为什么wx:for-items列表渲染[object Object]?

为什么wx:for-items列表渲染[object Object]?

addAttributeType: function (e) {
    let idx = e.currentTarget.dataset.index;
    let arr = (this.data.attribute[`${idx}`].type) ? this.data.attribute[`${idx}`].type : [];
    let obj = new Object;
    obj["name"] = this.data.attributeType;
    obj["checked"] = false;
    arr.push(obj);
    this.setData({
      [`attribute[${idx}].type`]: arr,
      attributeType: '',
    })
    console.log("属性列表:::", this.data.attribute)
  },


<block wx:for-items="{{item.type}}" wx:key="items">
              <view class="tag_item" data-idx="{{idx}}" data-cur="{{index}}" catchtap="delAttributeType">
                <text>{{items.name}}</text>
              </view>
            </block>
回答关注问题邀请回答
收藏

2 个回答

  • Qiu (吉²)
    Qiu (吉²)
    2021-07-05

    已解决。我在父级view加了wx:for-index ,下一级wx:for-items循环的*this被改变了。把父级view的wx:for-index,放到子元素就好了。不知道这样表述对不对,如果不对,请指正。

    更新后的代码

    <block wx:for="{{attribute}}" wx:key="item">
          <view>
            <view class="flex-space title">
              <text>{{item.name}}</text>
              <button class="btn_like btn_off" data-index="{{index}}" catchtap="delAttribute">
                <text class="iconfont iconfont-off"></text>
              </button>
            </view>
            <view class="content">
              <view class="flex-space input_add">
                <input value="{{attributeType}}" type="text" placeholder="属性值" placeholder-style="color: #9089BC;"
                  cursor-spacing="49" confirm-type="next" bindinput="inputAttributeType" />
                <button class="btn_like btn_add" data-index="{{index}}" catchtap="addAttributeType">
                  <text class="iconfont iconfont-jia"></text>
                </button>
              </view>
              <view class="flex-center tag_box">
                <block wx:for-items="{{item.type}}" wx:for-index="idx"  wx:key="item">
                  <view class="tag_item" data-cur="{{idx}}" data-idx="{{index}}" catchtap="delAttributeType">
                    <text>{{item.name}}</text>
                  </view>
                </block>
              </view>
            </view>
          </view>
        </block>
    
    2021-07-05
    有用 1
    回复
  • Mr.Zhao
    Mr.Zhao
    2021-07-05
    wx:key="items"  items?
    


    2021-07-05
    有用 1
    回复
登录 后发表内容