var app = getApp();
// pages/movies/movies.js
Page({
onLoad: function (options) {
var gloabalBase = app.globalData.douBanBase;
var inTheatersURL = gloabalBase + "/v2/movie/in_theaters" +"?start=0&count=3";
var commningSoonURL = gloabalBase + "/v2/movie/coming_soon" + "?start=0&count=3";
var topURL = gloabalBase + "/v2/movie/top250" + "?start=0&count=3";
this.getMovieListData(inTheatersURL);
// this.getMovieListData(commningSoonURL);
// this.getMovieListData(topURL);
},
getMovieListData:function(url){
var that = this;
wx.request({
url:url ,
method: 'GET',
header: {
'Content-Type': 'json'
},
success: function (res) {
console.log(res.data);
that.processMovieData(res.data);
}
});
},
processMovieData:function(movieData){
var movies = [];
for(var item in movieData.subjects){
var subject = movieData.subjects[item];
var title = subject.title;
if(title.length >6){
title = title.substring(0,6)+"...";
}
var temp = {
title:title,
id:subject.id,
img: subject.images.large,
average: subject.rating.average
}
movies.push(temp);
}
this.setData({
movies : movies
});
console.log("movies:"+movies);
}
})
4年同步微信官方迭代,累计20000+人学习, 比微信官方更火爆!
了解课程