<button type="primary" bindtap="getNetWorkType">獲取網絡類型</button> <button type="primary" bindtap="getSystemInfo">獲取設備信息</button> <button type="primary" bindtap="onAccelerometerChange">監聽重力感應數據</button> <button type="primary" bindtap="onCompassChange">監聽羅盤數據</button>
Page({ data:{ text:"Page system" }, onLoad:function(options){ // 頁面初始化 options為頁面跳轉所帶來的參數 }, /** * 獲取當前網絡狀態 */ getNetWorkType: function() { wx.getNetworkType({ success: function(res) { console.log(res) } }) }, /** * 獲取系統信息 */ getSystemInfo: function() { wx.getSystemInfo({ success: function(res) { console.log(res) } }) }, /** * 監聽重力感應數據 * - 帶on開頭的都是監聽接收一個callback */ onAccelerometerChange: function() { wx.onAccelerometerChange(function(res) { console.log(res) }) }, /** * 監聽羅盤數據 */ onCompassChange: function() { wx.onCompassChange(function(res) { console.log(res) }) }, onReady:function(){ // 頁面渲染完成 }, onShow:function(){ // 頁面顯示 }, onHide:function(){ // 頁面隱藏 }, onUnload:function(){ // 頁面關閉 } })
<!-- item.wxml --> <template name="item"> <text>{{text}}</text> </template>
<import src="item.wxml"/> <template is="item" data="{{text: 'forbar'}}"/>
<view wx:for="{{items}}"> {{index}}: {{item.message}} </view> Page({ items: [{ message: 'foo', },{ message: 'bar' }] })
<view wx:for="{{array}}" wx:for-index="idx" wx:for-item="itemName"> {{idx}}: {{itemName.message}} </view>