比如电影列表页跳转到电影详情页
在movie.js获取movieId; processDoubanData: function (moviesDouban, settedKey, categoryTitle) {
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) + "...";
}
// [1,1,1,1,1] [1,1,1,0,0]
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] = {
categoryTitle: categoryTitle,
movies: movies
}
this.setData(readyData);
}
在列表页模板上添加点击事件,绑定movieId,就获取了movieId,因为模板不能引入js,所以在列表页js地方写点击事件 <template name="movieTemplate">
<view class="movie-container" catchtap="onMovieTap" data-movieId="{{movieId}}">
<image class="movie-img" src="{{coverageUrl}}"></image>
<text class="movie-title">{{title}}</text>
<template is="starsTemplate" data="{{stars:stars, score: average}}" />
</view>
</template>
onMovieTap:function(event){
var movieId = event.currentTarget.dataset.movieid;
wx.navigateTo({
url: "movie-detail/movie-detail?id="+movieId
})
},
在movie-detail.js
onLoad:function(options){
var movieId = options.id;
var url = app.globalData.doubanBase +"/v2/movie/subject/" + movieId;
}
|
请发表评论