其他的电影评分没有显示,查了一下appdata,是因为其他电影的评分处理出来的分数是0,0,0,0,0数组,觉得好奇怪,复用都是对的,求有没有共同问题的小伙伴。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | // 这是movie.js的代码 var util = require( '../../utils/util.js' ); var app = getApp(); Page({ data: { inTheaters:{}, comingSoon:{}, top250:{} }, onLoad: function (event){ var inTheatersUrl = app.globalData.doubanBase + "/v2/movie/in_theaters" + "?start=0&count=3" ; var comingSoonUrl = app.globalData.doubanBase + "/v2/movie/coming_soon" + "?start=0&count=3" ; var top250Url = app.globalData.doubanBase + "/v2/movie/top250" + "?start=0&count=3" ; this .getMovieListData(inTheatersUrl, "inTheaters" ); this .getMovieListData(comingSoonUrl, "comingSoon" ); this .getMovieListData(top250Url, ".top250" ); }, getMovieListData: function (url,settedKey){ var that = this ; wx.request({ url: url, method: 'GET' , header: { "Content-Type" : "application/xml" }, success: function (res) { console.log(res); that.processDoubanData(res.data,settedKey); }, fail: function () { console.log( "failed" ); } }) }, processDoubanData: function (moviesDouban,settedKey){ var movies = []; for ( var idx in moviesDouban.subjects){ var subject = moviesDouban.subjects[idx]; var title = subject.title; if (title.length >= 6){ title = title.substring(0,6) + "···" ; } var temp = { stars:util.convertToStarsArray(subject.rating.stars), title:title, average:subject.rating.average, coverageUrl:subject.images.large, movieId:subject.id } movies.push(temp); } var readyData = {}; readyData[settedKey] = { movies:movies }; this .setData(readyData); }, }) |
4年同步微信官方迭代,累计20000+人学习, 比微信官方更火爆!
了解课程