var
app =getApp();
Page({
data:{
},
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"
:
"json"
},
success:
function
(res){
console.log(res);
that.processDoubanData(res.data,settedKey);
},
fail:
function
() {
}
})
},
processDoubanData:
function
(moviesDouban,settedKey){
var
movies = [];
for
(
var
i=0,movsubs=moviesDouban.subjects;i<movsubs.length;i++){
var
subject = movsubs[i];
var
title = subject.title;
if
(title.length >= 0){
title = title.substring(0,6) +
"..."
;
}
var
temp = {
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);
}
})