收藏
回答

请问方法中要怎么获取到全局变量中的值?

问题模块
API和组件
我从getdata()获取数据之后.执行方法赋值给全局变量.但是在createSimulationData()方法中.我无法this出来全局变量的值.只能this出来wx.getSystemInfo里面的值.求指点我该怎么做?谢谢各位大神
var util = require('../../utils/util.js')
var wxCharts = require('../../utils/wxcharts.js');
var lineChart = null;
var app = getApp()
Page({
  data: {
    logs: [],
    boolean: false,
    strTemp: '0',
    temp: 27.00,
    humi: 53,
    strHumi: '0',
    lasttime: '',
    width: 0,
    height: 0,
    randommath: 0.3,
    zdata: [],
    userInfo: {},
    month: '',
    strmonth: '',
    day: 0,
    strcount: 0,
    t_width: 0
  },
  btnlightonclick: function () {
    var bol = this.data.boolean;
    this.setData({
      boolean: !bol
    })
  },
  btnlisttestonclick: function () {
    wx.navigateTo({
      url: '../list/list'
    })
  },
  touchHandler: function (e) {
    console.log(lineChart.getCurrentDataIndex(e));
    lineChart.showToolTip(e, {
      background: '#bebebe'
    });
  },
  createSimulationData: function () {
    var categories = [];
    var data = [];
    var th = this;
 
    for (var i = 0; i < 8; i++) {
      categories.push('2017-' + th.month + '-' + (th.day + (i + 1) - 9));
      data.push(th.temp + Math.random());
    }
 
    return {
      categories: categories,
      data: data
    }
  },
  onLoad: function () {
    console.log('onLoad')
    this.getdata();
    var windowWidth = 100;
    var that = this
    wx.getSystemInfo({
      success: function (res) {
        that.t_width = res.windowWidth;
         
        that.width = 200;//res.windowWidth
        //    console.log(that.width)  
        that.height = 150;// res.windowHeight
        that.randommath = Math.round(Math.random() * 7, 2);
        that.temp = 27;
        that.humi = 53;
        that.month = util.formatmonth(new Date())
        that.day = util.formatday(new Date())
 
      }
    })
getdata: function () {
  var that = this;  
  wx.request({
    url: 'https://website.defond.com.cn/WeChat_zjh/HappyFarm_WEChat.aspx',
    data: {
    },
    header: {
      "Content-Type": "applciation/json"
    },
    method: "GET",//
    success: function (res) {
      console.log(res.data);//
      var list = that.formatData(res.data.data),
        reccount = res.data.recordcount;
      that.strcount=reccount;
      console.log(list,reccount);
 
      that.setData({
        logs: res.data.data,
        strcount:reccount
         
 
      })
 
    },
    fail: function (err) { console.log(showRequestInfo()) },
    complete: function () { }
  })
},


最后一次编辑于  2017-05-21  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏关注问题回答

1 个回答

  • maq
    maq
    2017-05-21

    你要先搞清楚 that.xxx 和 that.data.xxx 的区别。另外,你这段代码里根本就没有什么“全局变量”,事实上,在小程序的编程环境里也不存在什么真正意义上的“全局变量”。

    2017-05-21
    赞同
    回复