<button type="primary" bindtap="getNetWorkType">獲取網(wǎng)絡(luò)類型</button> <button type="primary" bindtap="getSystemInfo">獲取設(shè)備信息</button> <button type="primary" bindtap="onAccelerometerChange">監(jiān)聽重力感應(yīng)數(shù)據(jù)</button> <button type="primary" bindtap="onCompassChange">監(jiān)聽羅盤數(shù)據(jù)</button>
Page({
data:{
text:"Page system"
},
onLoad:function(options){
// 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù)
},
/**
* 獲取當(dāng)前網(wǎng)絡(luò)狀態(tài)
*/
getNetWorkType: function() {
wx.getNetworkType({
success: function(res) {
console.log(res)
}
})
},
/**
* 獲取系統(tǒng)信息
*/
getSystemInfo: function() {
wx.getSystemInfo({
success: function(res) {
console.log(res)
}
})
},
/**
* 監(jiān)聽重力感應(yīng)數(shù)據(jù)
* - 帶on開頭的都是監(jiān)聽接收一個callback
*/
onAccelerometerChange: function() {
wx.onAccelerometerChange(function(res) {
console.log(res)
})
},
/**
* 監(jiān)聽羅盤數(shù)據(jù)
*/
onCompassChange: function() {
wx.onCompassChange(function(res) {
console.log(res)
})
},
onReady:function(){
// 頁面渲染完成
},
onShow:function(){
// 頁面顯示
},
onHide:function(){
// 頁面隱藏
},
onUnload:function(){
// 頁面關(guān)閉
}
})
<!-- 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>