作者:xiao孛,來(lái)自原文地址
一:頁(yè)面跳轉(zhuǎn)navigator與傳遞參數(shù)
頁(yè)面之間跳轉(zhuǎn)使用 navigator標(biāo)簽,wx.navigateTo ,wx.redirectTo
1、URL就是跳轉(zhuǎn)的頁(yè)面路徑.上面代碼中就是navigator目錄下的navigator頁(yè)面,title是參數(shù)。
navigator下redirect屬性是值在當(dāng)前頁(yè)打開.如果不加redirect就是跳轉(zhuǎn)到新頁(yè)面.都可以攜帶參數(shù)。
如果需要傳多個(gè)參數(shù), 用 & 鏈接即可
-
<navigator url="../navigator/navigator?title=我是navigate" >跳轉(zhuǎn)到新頁(yè)面</navigator>
-
<navigator url="../redirect/redirect?title=我是redirect" open-type="redirect">在當(dāng)前頁(yè)打開</navigator>
或者
-
// 跳轉(zhuǎn)到新頁(yè)面
-
wx.navigateTo({
-
url: "../navigator/navigator?title=我是navigate"
-
})
-
// 在當(dāng)前頁(yè)打開
-
wx.redirectTo({
-
url: ../redirect/redirect?title=我是redirect"
-
})
2、在跳轉(zhuǎn)的js代碼可以獲取到title參數(shù)
-
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
二:循環(huán)列表添加點(diǎn)擊事件和樣式
如果列表中項(xiàng)目的位置會(huì)動(dòng)態(tài)改變或者有新的項(xiàng)目添加到列表中,并且希望列表中的項(xiàng)目保持自己的特征和狀態(tài)(如 <input/> 中的輸入內(nèi)容,<switch/> 的選中狀態(tài)),需要使用 wx:key 來(lái)指定列表中項(xiàng)目的唯一的標(biāo)識(shí)符。
wx:key 的值以兩種形式提供
-
字符串,代表在 for 循環(huán)的 array 中 item 的某個(gè) property,該 property 的值需要是列表中唯一的字符串或數(shù)字,且不能動(dòng)態(tài)改變。
-
保留關(guān)鍵字 *this 代表在 for 循環(huán)中的 item 本身,這種表示需要 item 本身是一個(gè)唯一的字符串或者數(shù)字,如: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里設(shè)一個(gè)變量,比如userCellId(JS文件在下面
|