6 回复
页面 index.wxml:
< block wx:for = "{{detailArr}}" wx:key = "{{item.id}}" > < view id = "{{item.id}}" bindtap = "showDetail" >{{item.name}}</ view > < view wx:if = "{{item.active}}" >{{item.detail}}</ view > </ block > |
代码 index.js
const app = getApp(); Page({ data: { detailArr: [{ id: 1, name: '点我出现详情1' , detail: '详情1' , active: false , }, { id: 2, name: '点我出现详情2' , detail: '详情2' , active: false , }, ], }, showDetail(e) { this .setData({ detailArr: this .data.detailArr.map(item => { if (item.id == e.currentTarget.id) { item.active = !item.active; } return item; }) }); }, onLoad(options) { }, onReady() { }, onShow() { }, onHide() { }, onUnload() { }, onPullDownRefresh() { }, onReachBottom() { }, }) |
谢谢,果然有效。。。
detailArr:
this.data.detailArr.map(item => {
if (item.id == e.currentTarget.id) {
item.active = !item.active;
}
return item;
})
关键点在这,item => 请问这个表示什么?