<view data-index="{{index}}"> // 循环生成的view, index为循环对象的id
<block wx:for="{{stuff.score}}" wx:key="index">
<icon class='iconfont icon-xingxing_o'
catchtap='in_xin' id='{{index+1}}' data-userid='{{stuff.id}}' data-in='use_sc2' data-key="{{1}}" />
</block>
<block wx:for="{{stuff.count}}" wx:key="index">
<icon class='iconfont icon-xingxing'
catchtap='in_xin' id='{{index+1}}' data-userid='{{stuff.id}}' data-in='use_sc' data-key="{{1}}" />
</block>
</view>
页面代码如上,<block>为星号图标循环,如何取得data-index的值呢,循环的data为:
stuff: [
{ id: '175', post: '职位1', name: '张三', score: 0, count: 5 },
{ id: '141', post: '职位2', name: '李四', score: 0, count: 5 },
{ id: '132', post: '职位3', name: '王二麻', score: 0, count: 5 }]
你给icon加个data-index="{{index}}" 不就行了