小程序 页面到详情的id传递

比如电影列表页跳转到电影详情页

在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;


}

 

转载于:https://www.cnblogs.com/colorful-paopao1/p/7928999.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值