小程序实现循环输出折叠面板

wxml

<view style="margin:0 24rpx;width:702rpx;">
    <block wx:for="{{info}}" wx:key="{{index}}">
        <view class="info-list" data-index="{{index + 1}}" catchtap="onChangeShowState">
            <text class="info-name">{{item.question}}</text>
            <image class="youjiantou" src="../../../assets/icon/{{showIndex == index + 1 ? 'xiajt':'shangjt'}}.png"></image>
            <!-- <image src="../../../assets/icon/xiajt.png" class="youjiantou" animation="{{animationData}}"></image> -->
        </view>
        <view class="bright789_view_hide"  wx:if="{{showIndex == index + 1}}" >
            <text class="bright789-text">{{item.answer}}</text>
        </view>
    </block>
</view>

js

 data: {
      showIndex: 0
    },   

onChangeShowState: function (e) {
      console.log(e)
      if (e.currentTarget.dataset.index != this.data.showIndex) {
        this.setData({
          showIndex: e.currentTarget.dataset.index
        })
      } else {
        this.setData({
          showIndex: 0
        })
      }
    },

我是请求的后端数据
  onShow: function () {
      var nowShow = this.data.selectShow;
        var that = this
        wx.request({
            url: api.jc.api,
            method: 'GET',
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            data: {
                act: 'help',
                keys: '202cb962ac59075b964b07152d234b70',
            },
            success: function (res) {
              // console.log(res)
                if (res.data.code == 200) {
                    var info = res.data.result
                    for (var i in info){
                        info[i] = {
                            question: info[i].question,
                            typeId: i,
                            answer: info[i].answer,
                            showView: false
                        }
                    }
                    that.setData({
                        info: info,
                    })
                } else {
                  showView: "",
                    wx.showToast({
                        title: res.data.message,
                        image: "../../../assets/icon/warning.png",
                    });
                }
            },
        });
    },

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值