企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### 实现跳转详情页面 `movie-template.wxml` ~~~html ***<view class="movie-container" catchtap="onMovieTap" data-movieId="{{movie.movieId}}"> <image class="movie-img" src="{{movie.coverageUrl}}"></image> <text class="movie-title">{{movie.title}}</text> <template is="starsTemplate" data="{{stars:movie.stars,score:movie.average}}"/> </view> ~~~ `movies.js` ~~~javascript onMovieTap:function(event){ var movieId = event.currentTarget.dataset.movieid; console.log(movieId); wx.navigateTo({ url: 'movie-detail/movie-detail?movieId='+movieId, }) }, ~~~ `movie-detail.js` ~~~javascript var util = require('../../../utils/util.js'); var app = getApp(); Page({ data: { }, onLoad: function (options) { var movieId = options.movieId; var url = app.globalData.doubanBase+"/v2/movie/subject/"+movieId; util.http(url,this.processDoubanData); }, processDoubanData:function(data){ console.log(data); }, ~~~ ### 继续处理数据 ~~~javascript processDoubanData:function(data){ var director = { avatar: "", name: "", id: "" } if (data.directors[0] != null) { if (data.directors[0].avatars != null) { director.avatar = data.directors[0].avatars.large; } director.name = data.directors[0].name; director.id = data.directors[0].id; } console.log(data); var movie = { movieImg: data.images ? data.images.large : "", country: data.countries[0], title: data.title, originalTitle: data.original_title, wishCount: data.wish_count, commentCount: data.comments_count, year: data.year, genres: data.genres.join("、"), stars: util.convertToStarsArray(data.rating.stars), score: data.rating.average, director: director, casts: util.convertToCastString(data.casts), castsInfo: util.convertToCastInfos(data.casts), summary: data.summary }; this.setData({ movie: movie }); ~~~ utils.js ~~~javascript function convertToCastString(casts) { var castsjoin = ""; for (var idx in casts) { castsjoin = castsjoin + casts[idx].name + "/"; } return castsjoin.substring(0, castsjoin.length - 2); } function convertToCastInfos(casts) { var castsArray = []; for (var idx in casts) { var cast = { img: casts[idx].avatars ? casts[idx].avatars.large : "", name: casts[idx].name } castsArray.push(cast); } return castsArray; } module.exports = { convertToStarsArray:convertToStarsArray, http:http, convertToCastString: convertToCastString, convertToCastInfos: convertToCastInfos } ~~~