首页中有
- 搜索框模块
- 轮播图模块
- 正在上映电影模块
- 即将上映电影模块
- 豆瓣电影Top250一共5个模块
- 正在上映电影
- 即将上映电影
- 豆瓣电影Top250模块的数据
分别从数据库的
- in_theaters
- coming_soon
- top250 3个集合中获取
在data的boards属性中定义3个集合的名称,修改index.js,代码如下
data: {boards: [{ key: 'in_theaters' },{ key: 'coming_soon' },{ key: 'top250' }]}}
定义retrieveData函数,根据集合名称获取数据,代码如下。
retrieveData(index) {var that = this;const db = wx.cloud.database();db.collection(this.data.boards[index].key).get().then(res =>{var boards = that.data.boards;boards[index].title = res.data[0].title;boards[index].movies = res.data[0].subjects;that.setData({ boards: that.data.boards });})}
在onLoad函数里,判断isShow为true后,调用retrieveData函数
因为要从3个集合中获取数据,所以需要调用3次,最终onLoad代码如下
onLoad: function (options) {wx.getStorage({key: 'isShow',success: res => {this.retrieveData(0)this.retrieveData(1)this.retrieveData(2)},fail: function (res) {wx.redirectTo({url: '/pages/splash/splash',})},})}
