页面部分js代码如下:
getHeight:function(){
var that = this;
const titleHeight = [];
const rowHeight = 36 / 750 * wx.getSystemInfoSync().windowWidth;
const row = [];
// 处理标题和简介的行数
wx.createSelectorQuery().selectAll('.title').boundingClientRect(function (rect) {
for (var i = 0; i < that.data.listData.length; i++) {
titleHeight[i] = rect[i].height;
row[i] = Math.round(titleHeight[i] / rowHeight);
var bb = 'abstracts[' + i + ']'
if (row[i] > 1) {
that.setData({
[bb]: "abstracts1"
});
} else {
that.setData({
[bb]: "abstracts2"
});
}
}
}).exec();
},
注意:.title是你自己的类名,此处使用for循环是因为我页面的数据是for循环出来的。