在首页或列表页单击进入电影详情页

修改app.json,添加item详情页配置,代码如下

  1. {
  2. "pages": [
  3. "pages/index/index",
  4. "pages/splash/splash",
  5. "pages/list/list",
  6. "pages/item/item"
  7. ]
  8. }

接下来,在item.js中请求subject集合数据,代码如下

  1. var db = wx.cloud.database();
  2. db.collection("subject")
  3. .get()
  4. .then(res =>{
  5. console.log(res)
  6. that.setData({ movie: res.data[0]});
  7. })

在实际开发中会使用从上一页面传过来的id作为参数,请求服务器当页的详情数据

本案例中直接使用subject集合的第一条数据作为详情页数据
把请求到的数据保存在data的movie属性中显示在页面上

详情页的代码如下

  1. <view class="weui-article">
  2. <view class="weui-article__section">
  3. <image class="weui-article__img" src="{{ movie.images.large }}"
  4. mode="aspectFit" style="width: 100%;height: 800rpx" />
  5. </view>
  6. <view class="weui-article__h1">{{ movie.title }}({{ movie.year }})</view>
  7. <view class="weui-article__section">
  8. <view class="weui-media-box__info" style="margin-top:10rpx;">
  9. <view class="weui-media-box__info__meta">评分:{{ movie.rating.average }}</view>
  10. </view>
  11. <view class="weui-media-box__info" style="margin-top:10rpx;">
  12. <view class="weui-media-box__info__meta">导演:
  13. <block wx:for="{{ movie.directors }}" wx:key="{{ item.id }}"> {{ item.name }} </block>
  14. </view>
  15. </view>
  16. <view class="weui-media-box__info" style="margin-top:10rpx;">
  17. <view class="weui-media-box__info__meta">主演:
  18. <block wx:for="{{ movie.casts }}" wx:key="{{ item.id }}"> {{ item.name }} </block>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="weui-article__section">
  23. <view class="weui-article__p">
  24. {{ movie.summary }}
  25. </view>
  26. </view>
  27. </view>