小程序列表循環出來的list是不一樣接口賦的值

需求:首頁有三個列表,樣式形式都是同樣的,能夠循環展現,可是循環的內容list部分是來自於不一樣的三個接口。

data: {
indexList:[{
      name: "中考體能突擊營",
            value: "fitness_evaluate_combo",
            list: [],
            option: 0
        }, {
            name: "中考體能培訓",
            value: "fitness_train_combo",
            list: [],
            option: 1
        }, {
      name: "少兒體育培訓",
            value: "children_train_combo",
            list: [],
            option: 2
        }, {
      name: "精品訓練營",
            value: "train_camp_combo",
            list: [],
            option: 3
        }, {
      name: "精品私教課",
            value: "personal_training_combo",
            list: [],
            option: 4
        }]
}
this.data.indexList.forEach(function(e, index) {
    var url = "/v2/home/recommend/courses/" + e.value;
    call.myRequest(url, that.listCoursesSuc, "GET", myData, '', e.value)
})
成功後調用方法賦值
listCoursesSuc: function(data, res, arg) {
        var that = this
        this.data.indexList.forEach(function(e, index) {
            if (e.value == arg) {
                let updata = `indexList[${e.option}].list`
                that.setData({
                    [updata]: data.value
                })
            }
        })
    },
相關文章
相關標籤/搜索