1、小程序里的点击事件
<
text
id=
'{{index}}'
bindtap=
'bindItemTap'> click me
</
text
>
绑定事件bindItemTap id为{{index}}。由于这是单个的绑定,这里不容易出错。
重点: 对于列表渲染之后的情况,需要注意id写的地方,通过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
>
注:上下两个text 在这里的区别,
上面是对text进行了id 和事件绑定,在事件event中能够console到数据
下面是对view进行了id和事件绑定,在事件event中不能够console到数据id
2、点击事件到对应的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、