動態(tài)設(shè)置列表中的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();
//動態(tài)取出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
//異步執(zhí)行所以只能放在這刷新 不能放在for循環(huán)外刷新
this.setData({
dynamicList: this.data.list
})
})
}
console.log('query after')