wx:for 动态绑定Page.data值
发布于 7 年前 作者 weijun 18413 次浏览 来自 问答

wx:for不能动态绑定Page.data的值吗?比如

Page.data({

   data_index:[0,1,2],

   page0:{},

   page1:{}

})

<view wx:for="{{data_index}}">

<view wx:for="{{“page”+index}}">

view>

2 回复

不支持!

想到了一个变通的方法

getUserCouponCodeList:function(e){

    var that=this;

    var status = e? e.currentTarget.dataset.status:0;

    var page=this.data[“page”+status] || 0;

    var changeData = {};

    changeData[“status”] = status;

    app.request({

        url: ‘Coupon/getUserCouponCodeList’,

        data: {

        status: status,

        page:page+1

        },

        success: function (res) {

            if (res.data.status == 1) {

                var couponCodeListStatus = that.data[“couponCodeList”+status] || [];

                var result = res.data.data || [];

                couponCodeListStatus = couponCodeListStatus.concat(result);

                changeData[“couponCodeList” + status] = couponCodeListStatus;

                changeData[“couponCodeList”] = couponCodeListStatus;

                changeData[“page”+status] = page+1;

                that.setData(changeData);

            }

        }

    })

}

回到顶部