前端页面
<
view
class=
'line'
wx:for=
"{{problemList}}"
bindtap=
'clickLine'
id=
"{{item.id}}">
<
view
class=
"lineTitle weui-cell__bd "
>
{{item.firstTitle}}
</
view
>
<
view
class=
"lineSencond {{item.open ? 'show' : ''}}"
>
<
view
class=
"lineSencond-con">
<
text
>Q {{item.sencondTitle}}
</
text
>
<
view
class=
"con">
<
text
> {{item.answer}}
</
text
>
</
view
>
</
view
>
</
view
>
</
view
>
wxss 中 设置默认是隐藏的 display:none;
添加的class默认为display:block;
js点击后给标签加上class之后,display变成block
clickLine:
function(e){
var id = e.currentTarget.id;
console.log(id)
var list =
this.data.problemList;
for (
var i =
0, len = list.length; i < len; ++i) {
if (list[i].id == id) {
list[i].open = !list[i].open
}
else {
list[i].open =
false
}
}
this.setData({
problemList: list
});
},