movie js
onLoad:function(event){
var intheatersUrl = app.globalData.doubanBase + "/v2/movie/in_theaters" + "?star=0&count=3";
var comingSoonUrl = app.globalData.doubanBase + "/v2/movie/coming_soon" + "?star=0&count=3";
var top250Url = app.globalData.doubanBase + "/v2/movie/top250" + "?star=0&count=3";
this.getMoviesList(intheatersUrl,"intheaters");
this.getMoviesList(comingSoonUrl,"comingSoon");
this.getMoviesList(top250Url,"top250");
},
getMoviesList:function(url,settedKey){
var that = this;
wx.request({
url: url,
method: 'GET',
header: {
"content-Type": "application/wxml",
},
success: function (res) {
console.log(res);
that.processdoubanData(res.data, settedKey);
},
fail: function (res) {
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 = {
title : title,
average : subject.rating.average,
coverageUrl : subject.images.large,
movieId : subject.id
};
movies.push(temp);
}
var readyData ={};
readyData[settedKey] = {
movies : movies
};
// this.setData({
// movieLists : readyData
// });
this.setData(readyData);
}
movie wxmld代码
<view class='movies-template'>
<template is="movieListTemplate" data ="{{...intheaters}}" />
</view>
<view class='movies-template' >
<template is="movieListTemplate" data ="{{...comingSoon}}" />
</view>
<view class='movies-template'>
<template is="movieListTemplate" data ="{{...top250}}" />
</view>
movie-list-template 代码
<view class='movies-container'>
<block wx:for="{{movies}}" wx:for-item="movie">
<template data="{{...movie}}" is="movieTemplate" />
</block>
</view>