weex icon indicating copy to clipboard operation
weex copied to clipboard

repeat 里绑定onclick=function($index),index打印出来是undefined,急!!!

Open solaronke opened this issue 9 years ago • 5 comments

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,求助!!!困扰了很久,找不到问题所在。

solaronke avatar Jan 11 '17 09:01 solaronke

onclick=function({{$index}})

这样试试?

luoei avatar Jan 11 '17 10:01 luoei

onclick="someFunction($index)" 这样就可以了

SimonTal avatar Jan 13 '17 01:01 SimonTal

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.

YorkShen avatar Feb 18 '19 12:02 YorkShen

This issue is outdated for a long time and will be closed now. You can create a new one if you still have questions.

Hanks10100 avatar May 16 '21 10:05 Hanks10100

This issue is outdated for a long time and will be closed now. You can create a new one if you still have questions.

Hanks10100 avatar May 16 '21 10:05 Hanks10100