标签:ndt OLE str 文件 nav view targe 取值 this
1、wx:for渲染后传值问题:
用wx:for渲染后,如果想在绑定的事件中获取点击项中的数据,则在wx:for的标签的属性中要加入data-item属性,具体如下:
a.wml文件
<view wx:for="{{MeetingRoom}}" bindtap=‘fordetails‘ data-name="{{item.name}}">
<view >
<view >
<view >{{item.name}}</view>
<view >地址:{{item.location}}</view>
</view>
</view>
a.js文件
Page({
data: {
MeetingRoom:[{
id:"1",
name:"1号会议室",
location:"1楼101室"
},{
id: "2",
name: "2号会议室",
location: "2楼202室"
},{
id: "3",
name: "3号会议室",
location: "3楼303室"
},{
id: "4",
name: "4号会议室",
location: "4楼404室"
}, {
id: "5",
name: "5号会议室",
location: "5楼505室"
}]
},
fordetails:function(e){
console.log(e.currentTarget.dataset.name)
wx.navigateTo({
url: ‘../detail/detail‘,
})
})
data-item中设置的key对应的value就可以在e.currentTarget.dataset中获取到
2、跨页面传值
若想进行跨页面传值,则需要在页面跳转语句的地址中追加需要传的值,代码如下:
1 wx.navigateTo({ 2 url: ‘../detail/detail?name=1号会议室‘ 3 })
取值可以在跳转页面的onLoad函数中加载,代码如下:
1 onLoad: function (options) { 2 this.setData({ 3 roomname:options.name 4 }) 5 }
标签:ndt OLE str 文件 nav view targe 取值 this
原文地址:https://www.cnblogs.com/kedray/p/9061748.html