1.微信小程序dataset undefined ??
2.如何获取数组index索引?
3.获取节点的属性,width ,height,left,right等等
方法一(一般用这个获取数据,记得要bindtap点击执行这个函数才能获取到currentTarget.dataset):
wxml:
点击获取data-id绑定的id值
js:
a:function(e){
console.log(event) //打印出view中所有属性的值,包括“点击获取data-id绑定的id值”
console.log(event.currentTarget.dataset.id) //打印出data-id绑定的id值
console.log(event.currentTarget.dataset.haha) //打印出index的值
console.log(event.currentTarget.id) //打印出aabb
}
方法二:
wxml:
点击获取data-id绑定的id值
js:
a:function(){
wx.createSelectorQuery().select('#eee').boundingClientRect(function (rect) {
console.log(rect.dataset.id) // 打印节点的dataset中的id值,即data-id绑定的值
rect.id // 节点的ID
rect.dataset // 节点的dataset
rect.left // 节点的左边界坐标
rect.right // 节点的右边界坐标
rect.top // 节点的上边界坐标
rect.bottom // 节点的下边界坐标
rect.width // 节点的宽度
rect.height // 节点的高度
}).exec()
}
官方微信开发文档新方法说明地址:https://developers.weixin.qq.com/miniprogram/dev/api/NodesRef.boundingClientRect.html
或者:
https://developers.weixin.qq.com/miniprogram/dev/api/wxml-nodes-info.html?search-key=wxml%E8%8A%82%E7%82%B9
转发————原文链接:https://blog.csdn.net/qq_31752115/article/details/85309475