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

论坛 期权论坛 脚本     
匿名技术用户   2020-12-29 14:54   26   0

微信小程序开发文档链接

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

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP