微信小程序request请求动态获取数据

微信小程序开发文档连接php

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>
相关文章
相关标签/搜索