美文网首页
小程序列表中组件高度获取

小程序列表中组件高度获取

作者: 银弹星空 | 来源:发表于2023-03-01 10:04 被阅读0次

动态设置列表中的id

      <view class="content_bg" style="margin-left: 80rpx;" wx:for="{{list}}">
        <text class="conts  {{!item.openContent?'close_content':''}}" id="content{{index}}">{{tools.getNotNullStr(item.content)}}</text>
        <text class="showBtn" wx:if="{{item.contentLine>=3}}" style="color: #2F6BB1;" data-index="{{index}}" catchtap="openContent" hover-stop-propagation='true'>{{item.openContent?"收起":"展开"}}</text>
      </view>

界面加再过之后在获取text高度

    console.log('query before')
    for (let index = 0; index < this.data.list.length; index++) {
      var query = wx.createSelectorQuery();
//动态取出view id
      query.select(`#content${index}`).boundingClientRect()
      query.exec((res) => {
        console.log("height==", res[0].height)
        this.data.list[index].contentLine = res[0].height / 25
        //异步执行所以只能放在这刷新 不能放在for循环外刷新
        this.setData({
          dynamicList: this.data.list
        })
      })
    }
    console.log('query after')

相关文章

网友评论

      本文标题:小程序列表中组件高度获取

      本文链接:https://www.haomeiwen.com/subject/zlvrldtx.html