### 将星星值转化为数组
`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>
~~~