需求:首页有三个列表,样式形式都是一样的,可以循环展示,但是循环的内容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
})
}
})
},