欢迎光临,了解微信小程序开发,就上易用通!

微信小程序页面跳转navigator与传递参数,循环列表添加点击事件和样式 ...

发布:2018-04-18 09:39浏览: 来源:网络 作者:cola

作者:xiao孛,来自原文地址

 

一:页面跳转navigator与传递参数

页面之间跳转使用 navigator标签,wx.navigateTo ,wx.redirectTo

1、URL就是跳转的页面路径.上面代码中就是navigator目录下的navigator页面,title是参数。 
navigator下redirect属性是值在当前页打开.如果不加redirect就是跳转到新页面.都可以携带参数。

如果需要传多个参数, 用 & 链接即可

 

				
  1. <navigator url="../navigator/navigator?title=我是navigate" >跳转到新页面</navigator>
  2. <navigator url="../redirect/redirect?title=我是redirect" open-type="redirect">在当前页打开</navigator>

或者

 

				
  1. // 跳转到新页面
  2. wx.navigateTo({
  3. url: "../navigator/navigator?title=我是navigate"
  4. })
  5. // 在当前页打开
  6. wx.redirectTo({
  7.     url: ../redirect/redirect?title=我是redirect"
  8. })

2、在跳转的js代码可以获取到title参数

 

				
  1. Page({
  2. data:{
  3. title: "",
  4. },
  5. onLoad: function(options) {
  6. this.setData({
  7. title: options.title
  8. })
  9. }
  10. })

文件引用:

https://mp.weixin.qq.com/debug/wxadoc/dev/component/navigator.html?t=1476197487811

https://www.jianshu.com/p/0135769db89c

 

二:循环列表添加点击事件和样式

如果列表中项目的位置会动态改变或者有新的项目添加到列表中,并且希望列表中的项目保持自己的特征和状态(如 <input/> 中的输入内容,<switch/> 的选中状态),需要使用 wx:key 来指定列表中项目的唯一的标识符。

wx:key 的值以两种形式提供

  • 字符串,代表在 for 循环的 array 中 item 的某个 property,该 property 的值需要是列表中唯一的字符串或数字,且不能动态改变。
  • 保留关键字 *this 代表在 for 循环中的 item 本身,这种表示需要 item 本身是一个唯一的字符串或者数字,如:numberArray: [1, 2, 3, 4]  wxml文件:
 

				
  1. <view class="userList" wx:for="{{items}}" wx:key="{{item.userId}} wx:for-index="idx"">
  2. <view class="{{userCellId==idx?'userCellActive':'userCell'}}" data-idx="{{idx}}" bindtap="userListAction">{{item.name}}</view>
  3. </view>

1、page.data里设一个变量,比如userCellId(JS文件在下面






免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。