欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序ajax實(shí)現(xiàn)請(qǐng)求服務(wù)器數(shù)據(jù)及模版遍歷數(shù)據(jù)功能示例

 更新時(shí)間:2017年12月15日 14:08:23   作者:XiaoBaiduQs  
這篇文章主要介紹了微信小程序ajax實(shí)現(xiàn)請(qǐng)求服務(wù)器數(shù)據(jù)及模版遍歷數(shù)據(jù)功能,結(jié)合實(shí)例形式分析了微信小程序ajax調(diào)用及模板wx:for循環(huán)列表渲染相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了微信小程序ajax實(shí)現(xiàn)請(qǐng)求服務(wù)器數(shù)據(jù)及模版遍歷數(shù)據(jù)功能。分享給大家供大家參考,具體如下:

昨天下載了一個(gè)微信小程序的開發(fā)者工具,大概看了一下文檔,簡(jiǎn)單的用他的方法實(shí)現(xiàn)了ajax請(qǐng)求。

微信小程序文檔地址:
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1474632113_xQVCl

頭部標(biāo)題和底部tab配置都在 app.json文件中,底部tab位最少兩個(gè),最多五個(gè)。下面是app.json文件代碼和相關(guān)注釋

{
 "pages":[
  "pages/index/index",
  "pages/tucao/tucao",
  "pages/center/center"
 ],
 "window":{
  "backgroundTextStyle":"",
  "navigationBarBackgroundColor": "red",
  "navigationBarTitleText": "一個(gè)標(biāo)題而已",
  "navigationBarTextStyle":"white"
 },
 "tabBar": {
  "list": [{
   "pagePath": "pages/index/index",
   "text": "首頁(yè)",
   "iconPath": "/images/public/menu-cd.png",
   "selectedIconPath": "/images/public/menu.png"
  },{
   "pagePath": "pages/tucao/tucao",
   "text": "吐槽",
   "iconPath": "/images/public/hot-cd.png",
   "selectedIconPath": "/images/public/hot.png"
  },{
   "pagePath": "pages/center/center",
   "text": "我的",
   "iconPath": "/images/public/center-cd.png",
   "selectedIconPath": "/images/public/center.png"
  }],
  "borderStyle": "white"
 }
}

這里我是通過(guò) 微信小程序wx.request實(shí)現(xiàn)ajax請(qǐng)求服務(wù)器數(shù)據(jù)的,一個(gè)程序里面最多能有五個(gè)這樣的請(qǐng)求。下面是index.js的代碼

//index.js
//獲取應(yīng)用實(shí)例
var app = getApp()
Page({
 data: {
  motto: 'Hello World',
  userInfo: {},
  Industry:{}
 },
 onLoad: function (res) {
  var that = this
  //調(diào)用應(yīng)用實(shí)例的方法獲取全局?jǐn)?shù)據(jù)
  app.getUserInfo(function(userInfo){
   //更新數(shù)據(jù)
   that.setData({
    userInfo:userInfo
   })
  })
  wx.request({
   url: 'http://xx.xxxxx.com/xxx.php',//上線的話必須是https,沒有appId的本地請(qǐng)求貌似不受影響
   data: {},
   method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
   // header: {}, // 設(shè)置請(qǐng)求的 header
   success: function(res){
    console.log(res.data.result)
    that.setData({
     Industry:res.data.result
    })
   },
   fail: function() {
    // fail
   },
   complete: function() {
    // complete
   }
  })
 }
})

其中http://xx.xxxxx.com/xxx.php的返回?cái)?shù)據(jù)格式是一個(gè)json,格式如下

展示頁(yè)面就簡(jiǎn)單了,變量{{array}} 微信模版遍歷數(shù)據(jù)使用 wx:for 。index.wxml代碼如下:

<!--index.wxml-->
<view class="container">
 <view bindtap="bindViewTap" class="userinfo">
  <image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
  <text class="userinfo-nickname">{{userInfo.nickName}}</text>
 </view>
</view>
<view wx:for="{{Industry}}" wx:ket="{{index}}">
  {{index}}:{{item.name}}
</view>

希望本文所述對(duì)大家微信小程序開發(fā)有所幫助。

相關(guān)文章

最新評(píng)論