一:页面跳转navigator与传递参数
页面之间跳转使用 navigator标签,wx.navigateTo ,wx.redirectTo
1、URL就是跳转的页面路径.上面代码中就是navigator目录下的navigator页面,title是参数。
navigator下redirect属性是值在当前页打开.如果不加redirect就是跳转到新页面.都可以携带参数。
如果需要传多个参数, 用 & 链接即可
<navigator url="../navigator/navigator?title=我是navigate" >跳转到新页面</navigator>
<navigator url="../redirect/redirect?title=我是redirect" open-type="redirect">在当前页打开</navigator>
或者
// 跳转到新页面
wx.navigateTo({
url: "../navigator/navigator?title=我是navigate"
})
// 在当前页打开
wx.redirectTo({
url: ../redirect/redirect?title=我是redirect"
})
2、在跳转的js代码可以获取到title参数
Page({
data:{
title: "",
},
onLoad: function(options) {
this.setData({
title: options.title
})
}
})
文件引用:
https://mp.weixin.qq.com/debug/wxadoc/dev/component/navigator.html?t=1476197487811
二:循环列表添加点击事件和样式
如果列表中项目的位置会动态改变或者有新的项目添加到列表中,并且希望列表中的项目保持自己的特征和状态(如 <input/> 中的输入内容,<switch/> 的选中状态),需要使用 wx:key 来指定列表中项目的唯一的标识符。
wx:key 的值以两种形式提供
字符串,代表在 for 循环的 array 中 item 的某个 property,该 property 的值需要是列表中唯一的字符串或数字,且不能动态改变。
保留关键字 *this 代表在 for 循环中的 item 本身,这种表示需要 item 本身是一个唯一的字符串或者数字,如:numberArray: [1, 2, 3, 4] wxml文件:
<view class="userList" wx:for="{{items}}" wx:key="{{item.userId}} wx:for-index="idx"">
<view class="{{userCellId==idx?'userCellActive':'userCell'}}" data-idx="{{idx}}" bindtap="userListAction">{{item.name}}</view>
</view>
1、page.data里设一个变量,比如userCellId(JS文件在下面