多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
### 将星星值转化为数组 `util.js` ~~~javascript function convertToStarsArray(stars) { var num = stars.toString().substring(0, 1); var array = []; for (var i = 1; i <= 5; i++) { if (i <= num) { array.push(1); } else { array.push(0); } } return array; } module.exports = { convertToStarsArray:convertToStarsArray } ~~~ `movies.js` ~~~javascript var util = require('../../utils/util.js'); var temp = { stars:util.convertToStarsArray(subject.rating.stars), title:title, average:subject.rating.average, coverageUrl:subject.images.large, movieId:subject.id } ~~~ `movie-template.wxml` ~~~html <template name="movieTemplate"> <view class="movie-container"> <image class="movie-img" src="{{movie.coverageUrl}}"></image> <text class="movie-title">{{movie.title}}</text> <template is="starsTemplate" data="{{stars:movie.stars,score:movie.average}}"/> </view> </template> ~~~ `stars-template.wxml` ~~~html <template name="starsTemplate"> <view class="stars-container"> <view class="stars"> <block wx:for="{{stars}}" wx:for-item="i" > <image wx:if="{{i}}" src="/images/icon/star.png"></image> <image wx:else src="/images/icon/none-star.png"></image> <!-- <image src="/images/icon/star.png"></image> <image src="/images/icon/star.png"></image> <image src="/images/icon/star.png"></image> <image src="/images/icon/star.png"></image> <image src="/images/icon/star.png"></image> --> </block> </view> <text class="star-score">{{score}}</text> </view> </template> ~~~