父组件index.wxml stalls是个数组 count的属性是字符串
<view class='stalls' wx:for="{{stalls}}" wx:key=''>
<stars count="{{item.count}}" />
</view>
</view>
自定义组件
stars.wxml
<view class='stall'>
<view>{{count}}</view>
<block wx:for="{{solid}}" wx:key="">
<image src='../../images/star-solid.png'></image>
</block>
<block wx:for="{{half}}" wx:key="">
<image src='../../images/star-half.png'></image>
</block>
<block wx:for="{{hollow}}" wx:key="">
<image src='../../images/star-hollow.png'></image>
</block>
</view>
stars.js
Component({
properties: {
count:String
},
data: {
// 这里是一些组件内部数据
solid: ' ',
half: ' ',
hollow: ' ',
},
onLoad: function () {
this.setData({
solid: parseInt(this.properties.count),
half: Math.ceil(5 - this.aproperties.count) - (5 - self.properties.count),
hollow: parseInt(5 - this.properties.count)
})
},
})
自定义组件内部的data里的数据没有变化