1. Click event in the applet
<
text
id
=
'{{index}}'
bindtap
=
'bindItemTap'>
click me
</
text
>
The bind event bindItemTap id is {{index}}. Since this is a single binding, it's less prone to error here.
Important: For the situation after the list is rendered, you need to pay attention to the place where the id is written, and you can see the specific data through the console.
<
view
class
=
'teamright'
>
<
view
class
=
"flex-item nametxt"
>
<
text
id
=
'{{index}}'
bindtap
=
'bindItemTap'>
{{index}} {{itemName.teamName}}
</
text
>
</
view
>
<
view
class
=
"flex-item jianjietxt "
id
=
'{{index}}' bindtap='bindItemTap'>
<
text
>
{{itemName.shanchang}}
</
text
>
</
view
>
</
view
>
Note: The difference between the upper and lower texts here,
The above is the id and event binding for the text, which can console to the data in the event event
The following is the id and event binding of the view, the data id cannot be consoled in the event event
2. Click the event to the corresponding js
bindItemTap:
function (e) {
//获取当前item的下标id,通过currentTarget.id
var index = e.currentTarget.id;
//var index=e.target.id
console.log(index);
console.log(e);
//用来实现跳转,并把传递数据
wx.navigateTo({
url:
'../teamdetail/teamdetail'+index})
}
注:在获取具体的内容时,可以通过console中看到数据,然后考虑currentTarget、target
来获取数据(currentTarget和target的区别)
3、