微信小程序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>
安静男孩
原文地址:https://www.cnblogs.com/xishaohui/p/9066126.html