repeat 里绑定onclick=function($index),index打印出来是undefined,急!!!
repeat 里绑定onclick=function($index),index打印出来是undefined,怎么都无法将$index传入click的function 中,例:
<template>
<div>
<div repeat="(index, person) in list" class="{{person.gender}}" onclick="selectindex($index)">
<text>{{index}} - {{person.nickname}}</text>
</div>
</div>
</template>
<style>
.male { background-color: #9999ff; }
.female { background-color: #ff9999; }
</style>
<script>
module.exports = {
data: {
list: [
{ gender: 'male', nickname: 'Li Lei' },
{ gender: 'female', nickname: 'Han Meimei' },
{ gender: 'male', nickname: 'Jim Green' }
]
},
methods: {
selectindex: function(index) {
alert(index);
}
}
}
</script>
alert出来的index是undefined,求助!!!困扰了很久,找不到问题所在。
onclick=function({{$index}})
这样试试?
onclick="someFunction($index)" 这样就可以了
This PR/issue doesn't receive response since Weex migrated to Apache two years ago and this repository is no longer active yet.
Feel free to ask question in new repository and thanks for your contribution.
This issue is outdated for a long time and will be closed now. You can create a new one if you still have questions.
This issue is outdated for a long time and will be closed now. You can create a new one if you still have questions.