直接代碼javascript
wxml代碼片斷java
<view class='ranksList' wx:for="{{ranksLb}}"> <view class='ranksListName'><image src='../image/icon-21.png'></image><text>{{item.name}}</text></view> <view class='ranksListNum'><label>下級:</label><text bindtap='tosubordinate' data-workerId='{{item.id}}'>{{item.subordinateNum}}-{{item.id}}</text></view> <view class='ranksListIphone'><image src='../image/icon-22.png'></image><text>{{item.mobile}}</text></view> </view>
js代碼片斷函數
//事件處理函數 tosubordinate: function (e) { var workerId = e.currentTarget.dataset.workerId; console.log("workerId------" + workerId); wx.navigateTo({ url: '../subordinate/subordinate?workerId=' + workerId }) },
結果 workerId undefined。url
OK,重點便在這裏。在組件中能夠定義數據,這些數據將會經過事件傳遞給 SERVICE。 書寫方式: 以data-開頭,多個單詞由連字符-連接,不能有大寫(大寫會自動轉成小寫)如data-element-type,最終在 event.target.dataset 中會將連字符轉成駝峯elementType。
這裏寫圖片描述
看代碼可知,這裏是自定義了一個名字爲id的dataset,所以在事件函數中,咱們能夠經過e.currentTarget.dataset.id訪問到綁定到該組件的自定義數據。spa
修改:code
//事件處理函數 tosubordinate: function (e) { var workerId = e.currentTarget.dataset.workerid; console.log("workerId------" + workerId); wx.navigateTo({ url: '../subordinate/subordinate?workerId=' + workerId }) },
主要修改了 e.currentTarget.dataset.workerid.xml
workerId –> workerid 解決。事件