收藏
回答

console data里面的数组为什么会是空呢?

// pages/checkoutlist/checkoutlist.js
const app = getApp();
var net, gross, bianhao = 0;
var packNum, towsName;
var bianhao_list = [];




Page({


  /**
   * 页面的初始数据
   */
  data: {
    orderId0,
    btnusetrue
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoadfunction(options{
    
    if (options.orderId == app.orderId) {
      this.setData({
        orderId: options.orderId
      })
    } else {
      this.setData({
        orderId: app.orderId
      })
    }
  },


  onShowfunction() {
    this.initTowsData()
  },


  scanCodefunction() {
    var that = this
    wx.scanCode({
      successfunction(res{
        net = res.result.substring(2023)
        console.log("net = ", net)
        gross = res.result.substring(1720)
        console.log("gross = ", gross)
        towsName = res.result.substring(37)
        console.log("towsName = ", towsName)
        packNum = res.result.substring(717)
        console.log("packNum = ", packNum)


        wx.request({
          url'https://hn2.api.okayapi.com/?&s=App.Table.CheckCreate&model_name=towsdata&data={"orderId":"' + app.orderId + '","packNum":"' + packNum + '","towsName":"0","gross":"' + gross + '","net":"' + net + '"}&check_field=packNum&app_key=88DE911C912A3CBB6279020C73DFC327',
          header: {
            'content-type''application/json' // 默认值
          },
          successfunction(res{
            console.log(res.data);
            if (res.data.data.err_code == 3) {
              wx.showToast({
                title'数据已存在',
              })
            } else {
              wx.showToast({
                title'上传成功',
              })
            }
          }


        })


        that.setData({
          net: res.result.substring(2023),


        })


      },
      failfunction(res{
        console.log("扫码失败 ")
      },


    })
  },
  upLoadfunction(e{
    wx.showModal({
      title'提示',
      content'是否全部扫码完成',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          var util = require('../../utils/util.js')
          var fache = util.formatTime(new Date());
          var state = 1
          wx.request({
            url'https://hn2.api.okayapi.com/?&s=App.Table.CheckCreate&model_name=towsLog&data={"orderId":"' + app.orderId + '","lic":"' + lic + '","fache":"' + fache + '","state":"' + state + '"}&check_field=packNum&app_key=88DE911C912A3CBB6279020C73DFC327',
            header: {
              'content-type''application/json' // 默认值
            },
            successfunction (res{
            }
          })


        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  initTowsDatafunction () {
    var that = this
    wx.request({
      url'https://hn2.api.okayapi.com/?&s=App.Table.FreeQuery&model_name=towsdata&logic=and&where=[["id", ">", "1"]]&page=1&perpage=50&is_real_total=1&app_key=88DE911C912A3CBB6279020C73DFC327',
      header: {
        'content-type''application/json' // 默认值
      },
      successfunction(res{
        that.setData({
          listData: res.data.data.list
        });


      }
    })
    wx.request({
      url'https://hn2.api.okayapi.com/?&s=App.Table.FreeQuery&model_name=towsClass&logic=and&where=[["id", ">", "0"]]&page=1&perpage=50&is_real_total=1&app_key=88DE911C912A3CBB6279020C73DFC327',
      header: {
        'content-type''application/json' // 默认值
      },
      successfunction(res{
        that.setData({
          towsClass: res.data.data.list
        })
      }
    })
    console.log(that.data)
    console.log(that.data.listData)
  }



})


回答关注问题邀请回答
收藏

1 个回答

  • 老张
    老张
    2020-01-20

    猜是异步的问题,数据还没有获取到。

    2020-01-20
    有用
    回复 3
    • 显龙
      显龙
      2020-01-20
      但是data里面显示又这个数据,倒数第二张图,然后再打印反而没有值
      2020-01-20
      回复
    • 老张
      老张
      2020-01-20回复显龙
      所以这种情况大概率是异步的问题啊。
      2020-01-20
      回复
    • 显龙
      显龙
      2020-01-20回复老张
      大神,我应该怎么处理
      2020-01-20
      回复
登录 后发表内容
问题标签