js
// 星星点击事件
scorestar: function (e) {
var scorestar = e.currentTarget.dataset.in;
var selectStar;
if (scorestar === 'use_sc2') {
selectStar = Number(e.currentTarget.id);
} else {
selectStar = Number(e.currentTarget.id) + this.data.selectStar;
}
this.setData({
selectStar: selectStar,
noselectStar: 5 - selectStar
})
}
data
selectStar:0, //选择的星星
noselectStar:5 //未选择的星星
wxml
<view class="scorebox">
<block wx:for="{{selectStar}}" wx:key="index">
<image catchtap='scorestar' id='{{index+1}}' data-in='use_sc2' src='/images/scorestar-full.png'></image>
</block>
<block wx:for="{{noselectStar}}" wx:key="index">
<image catchtap='scorestar' id='{{index+1}}' data-in='use_sc' src='/images/scorestar-empty.png'></image>
</block>
</view>
<view>{{selectStar}}星</view>
后台显示星星个数
<view class="starbox {{resolvedflag == '0' ? 'starhide' : ''}}">
回答满意度:
<view class="starlist">
<block wx:for="{{selectStar1}}" wx:key=''>
<image src='/images/scorestar-full.png'></image>
</block>
<block wx:for="{{selectStar2}}" wx:key=''>
<image src='/images/scorestar-empty.png'></image>
</block>
</view>
</view>
data:{
selectStar1: '', //展示星星
selectStar2: '', //展示星星
resolvedflag: ''
},
getQuestionDetail: function() {
let _this = this;
if (_this.data.scroll.requesting) {
return;
}
_this.showRequesting(true);
request(getHostUrl() + getQuestionDetailUrl(), {
questionid: _this.data.questionid,
start: _this.data.start,
}).then(
function(data) {
if (0 == _this.data.start) {
_this.setData({
question: data.data.question,
answerList: data.data.answer,
start: data.data.answer.length,
score: data.data.question.score,
resolvedflag: data.data.question.resolvedflag,
selectStar1: data.data.question.score,
selectStar2: 5 - data.data.question.score
}, function() {
_this.showRequesting(false);
});
} else {
_this.setData({
answerList: _this.data.answerList.concat(data.data.answer),
start: parseInt(_this.data.start) + data.data.answer.length
}, function() {
_this.showRequesting(false);
});
}
},
function(err) {
_this.showRequesting(false);
}
)
},
https://blog.csdn.net/qq_35713752/article/details/78770260