收藏
回答

自定义组件 事件改变 组件data 组件 不渲染?

var wait=false;

var rqzh = require('../../utils/util.js');

const app = getApp()

var dzid = [];

Component({

  properties: {

    hidden: {

      type: Boolean,

      value: true

    },

    heightd:{

     type:Number,

     value:0

    }

  },

  ready: function () {

    this.refresh();

   console.log('ready')

  },

  data: {

    dataList:[],

    bottom:false

  },

  methods: {

    getData: function () {

      const that = this;

  if (!wait){

        wx.cloud.callFunction({

          name: "editdata",

          data: {

            type: 'get',

           db: 'ssnew',

            skip: that.data.dataList.length,

            limit: 20,

            condition: {}

          },

          success(res) {

            if (res.result.data.length > 0) {

              var picture = [];

              var m = 0;

              var arr = [];

              for (var i = 0; i < res.result.data.length; i++) {

                arr[i] = { "id": res.result.data[i]._id, "title": res.result.data[i].title, "text": res.result.data[i].text, "user": res.result.data[i].user, "systime": rqzh.format_date(new Date(res.result.data[i].systime)), "dianzan": res.result.data[i].dianzan, "view": res.result.data[i].view, "picture": res.result.data[i].picture[0] }

                if (res.result.data[i].picture.length != 0) {

                  picture[m] = res.result.data[i].picture[0]

    m++

         }

              }

              that.data.dataList.push(arr)

              that.setData({

                dataList: that.data.dataList

              })

              wx.cloud.getTempFileURL({

                fileList: picture,

                success: res => {

                  for (var i = 0; i < res.fileList.length; i++) {

                    for (var a = 0; a < arr.length; a++) {

                      if (that.data.dataList[a].picture == res.fileList[i].fileID) {

                        that.data.dataList[a].picture = res.fileList[i].tempFileURL

                      }

                   }

                  }

     console.log('sss', that.data.dataList)

                  that.setData({

                    dataList: that.data.dataList

                  })

                wait=false

                },

   fail(res) {

                  console.log('下载图片失败', res)

                  wait = false

                }

              })

            }

            else {

             wx.showToast({

                title: '没有更多数据了……',

                icon: 'none'

              })

              setTimeout(function () {

                wx.hideToast()

              }, 2000)

              wait = false

              that.setData({

                bottom: true

              })           

           }

          },

          fail(res) {

           console.log("加载数据出错", res)

          }

        })

      },

    refresh: function (e) {

      var self = this;

        self.setData({

          bottom: false

        })

        self.getData();

    }

  }

  })

这是组件代码

<ssnew_list hiddend="false" heightd="500" id="ssnew_list"></ssnew_list>

这是页面代码,加载后不出现数据列表

这个是控制台显示,已经有数据


最后一次编辑于  2020-03-14
回答关注问题邀请回答
收藏

2 个回答

  • Mr.Zhao
    Mr.Zhao
    2020-03-14
    that.setData({
       dataList: that.data.dataList
    })
    为什么不写成 下面这种,你发的代码别人也运行不了,arr打印出来是个什么,加入你把arr写死呢?
    that.setData({
       dataList: arr
    })
    


    2020-03-14
    有用 1
    回复
  • hbzyliyong
    hbzyliyong
    2020-03-14

    ready: function () {

        this.refresh();

       console.log('ready')

      },


    这个启动后执行refresh,在调用getDate


    2020-03-14
    有用
    回复
登录 后发表内容
问题标签