위 챗 애플 릿 동적 바 인 딩 이벤트 및 이벤트 수정 스타일 구현
인 스 턴 스 코드
wxml
<scroll-view class="reportTypeScroll" scroll-x="true" scroll-left="{{toLeftNum}}">
<block wx:for-items="{{reportTypeList}}" wx:key="{{index}}">
<text type="primary" style="width:{{itemWidth}}rpx;" bindtap="bind{{item.id}}" data-typeid="{{item.id}}" class="{{currentId==item.id?'clickSel':'removeSel'}}">{{item.name}}</text>
</block>
</scroll-view>
js
var reportTypeList = [
{ name: " 1", id: "1" },
{ name: " 2", id: "2" },
{ name: " 3", id: "3" },
{ name: " 4", id: "4" },
{ name: " 5", id: "5" },
{ name: " 6", id: "6" },
{ name: " 7", id: "7" },
{ name: " 8", id: "8" },
{ name: " 9", id: "9" },
{ name: " 10", id: "10" },
{ name: " 11", id: "11" },
{ name: " 12", id: "12" }]
var pageObject = {
data: {
reportTypeList: reportTypeList,
num: 0,
toLeftNum: 0,
itemWidth: 150
}
}
for (var i = 0; i < reportTypeList.length; i++) {
(function (item) {
pageObject['bind' + item.id] = function (e) {
var id = parseInt(e.currentTarget.dataset.typeid)
this.setData({
currentId: id
})
}
})(reportTypeList[i])
}
Page(pageObject)
wxss
/**index.wxss**/
.reportTypeScroll {
margin: 40px 0px 20px 0px;
white-space: nowrap;
display: flex;
}
.clickSel {
color: red;
}
.removeSel {
color: black;
}
text {
height: 150rpx;
display: inline-block;
text-align: center;
}
읽 어 주 셔 서 감사합니다. 여러분 에 게 도움 이 되 기 를 바 랍 니 다.본 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!