微信小程序request請求動態獲取數據


微信小程序開發文檔鏈接

1 后台代碼:

 clickButton:function(){
    var that = this;
    wx.request({
      url: 'http://localhost:9096/admin.php/index/jj',
      method : 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      data : {},
      success: function (res) {
        //console.log(res.data);
        var t = this;
        var arr = new Array();
        arr = res.data;
        console.log(typeof (res.data));
        console.log(arr[0]);
        that.setData({
          user: res.data
        });
      }
    })
    this.setData({ msg: "Hello World" })
  }

關於this.setData函數設置綁定數據的問題,如果 在request請求函數外部可以直接使用,如果在其內部使用,會報異常。this不能在其直接使用需要在request請求函數外部

定義一個變量【名字隨意定義】,上面我定義的是一個that。

2 前台代碼:

<view wx:for = "{{user}}">{{item.username}}</view>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM