`more-movie.js`
~~~
var util = require('../../../utils/util.js');
var app = getApp();
onLoad: function (options) {
var category = options.category;
this.setData({
navigateTitle:category
})
var dataUrl = "";
switch (category) {
case "正在热映":
dataUrl = app.globalData.doubanBase + "/v2/movie/in_theaters";
break;
case "即将上映":
dataUrl = app.globalData.doubanBase + "/v2/movie/coming_soon";
break;
case "豆瓣Top250":
dataUrl = app.globalData.doubanBase + "/v2/movie/top250";
}
util.http(dataUrl, this.processDoubanData);
},
processDoubanData: function (moviesDouban) {
var movies = [];
for (var ids in moviesDouban.subjects) {
var subject = moviesDouban.subjects[ids];
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);
}
this.setData({
movies:movies
});
},
~~~
`utils.js`
~~~javascript
function http(url,callBack) {
var that = this;
wx.request({
url: url,
method: "GET",
success: function (res) {
callBack(res.data);
},
fail: function (error) {
},
});
}
module.exports = {
convertToStarsArray:convertToStarsArray,
http:http
}
~~~