const app = getApp(); Component({ properties: { course_id:Number, course_identity:Number, refresh: { type: Boolean, observer: function (v) { if (v) { //console.log("observer refresh"); this.refresh({refresh:1}); this.setData({ refresh: false }); } } } }, data: { }, attached(){ this.options = {page:1, limit:20}; this.refresh({refresh:1}); }, methods: { async refresh({refresh=0}={}){ if (refresh) { if (refresh == 1) { this.options.page = 1; var { options } = this; } else if (refresh == 2) { var { page, limit } = this.options; var options = { page: 1, per_page: page * limit }; } } else { this.options.page++; var { options } = this; } let {course_id} = this.data; let { activities } = await app.api("weapps.courses.course_activities")({ course_id, ...this.options}); if (!refresh) var activityGroups = this.getActivityGroups(activities, this.data.activityGroups); else var activityGroups = this.getActivityGroups(activities); this.setData({ activityGroups }); return activityGroups; }, getActivityGroups(activities, groups={}){ for(var item of activities){ var date = item.created_at.split(" ")[0]; if(date in groups) groups[date].push(item); else groups[date] = [item]; } console.log(groups); return groups; }, onReachBottom(){ this.refresh(); } } })