微信小程序ajax请求绑定数据简单实例

来源:互联网 发布:淘宝网图书松下幸之助 编辑:程序博客网 时间:2024/05/21 11:33

.wxml文件

<viewclass="flex-wrp"style="flex-direction:row;"wx:for="{{Industry}}"><viewclass="flex-item bc_green">({{index}}){{item.date}} {{item.high}} {{item.low}}{{item.notice}}</view></view><viewclass="tip"hidden="{{isshow}}">数据加载完成</view>
.js文件
// pages/list/list.jsPage({  /**   * 页面的初始数据   */  data: {    Industry:{},    isshow:true  },  /**   * 生命周期函数--监听页面加载   */  onLoad: function (res) {    var that = this     wx.request({      url: 'http://www.sojson.com/open/api/weather/json.shtml?city=杭州',       header: {        'content-type': 'application/json' // 默认值      },      success: function (res) {        console.log(res.data.data.forecast)        that.setData({          Industry: res.data.data.forecast        })        },      fail: function () {       console.log("fail")      },      complete: function () {         that.setData({           isshow:false         })      }     })  },  /**   * 生命周期函数--监听页面初次渲染完成   */  onReady: function () {    },  /**   * 生命周期函数--监听页面显示   */  onShow: function () {    },  /**   * 生命周期函数--监听页面隐藏   */  onHide: function () {    },  /**   * 生命周期函数--监听页面卸载   */  onUnload: function () {    },  /**   * 页面相关事件处理函数--监听用户下拉动作   */  onPullDownRefresh: function () {    },  /**   * 页面上拉触底事件的处理函数   */  onReachBottom: function () {    },  /**   * 用户点击右上角分享   */  onShareAppMessage: function () {    }})




原创粉丝点击