作者:xiao孛,來自原文地址
一:頁面跳轉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
http://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文件:
-
<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文件在下面
|