注:
凡是data-自定义值 的为自定义属性值
必须是data开头:例 data-postd="{{item.postId}}"
event.currentTarget.dataset 所有自定义属性的集合
a、post.wxml
//定义跳转事件 onTapdetail 定义传递的属性志data-postad
<
block
wx:for=
"{{posts_key}}"
wx:for-item=
"item">
<!--template -->
<
view
bindtap=
"onTapdetail"
data-postad=
"{{item.postId}}">
<
template
is=
"postItem"
data=
"{{...item}}"
/
>
</
view
>
</
block
>
b、post.js
/**跳转详情页 */
onTapdetail:
function(event){
var postad = event .currentTarget.dataset.postad //获取传递的值
console.log(postad);
wx.navigateTo({
//url:
'post-detail/post-detail' //跳转详情页 切记配置app.json文件
url:
'post-detail/post-detail?id='+postad //传递参数
})
},
c、post-detail.js接收参数
Page({
onLoad:
function (option) { //定义的id要一致
var postId=option.id
console.log(postId)
}
})