zoukankan      html  css  js  c++  java
  • 小程序加载云端数据库中的第二页数据,前端如何动态显示?

    export default class HelloLoading{
    
      constructor(collection_name,db){
        this.collection_name = collection_name
    
        this.db = db
        this.setPageCount(db)
      }
    
      pageCount = 0;
    setPageCount(db){ db.collection(this.collection_name).count({ success:function(res){ // console.log(res.total) this.pageCount = res.total }, fail: console.error }) }
    getPageCount(){ return this.pageCount } }

      

    如上,当请求getPageCount() 的时候,构造函数的setPageCount还没有执行结束呢!怎么办?

    回调函数!

    export default class HelloLoading{
    
      static pageCount = 0;
    
      constructor(collection_name){
        this.collection_name = collection_name
    
        this.db = wx.cloud.database()
       
      }
    
      setPageCount(callback){
    
        this.db.collection(this.collection_name).count({
          success:function(res){
            
            console.log(res.total)
            HelloLoading.pageCount = res.total
    
            callback()
          },
          fail: console.error
        })
    
      }
    
      getPageCount(){
        return HelloLoading.pageCount;
      }
    
    }
    

      外部调用的时候,使用

    loadingdata.setPageCount(function(){
          console.log(loadingdata.getPageCount())
        })
    

      

  • 相关阅读:
    17. Letter Combinations of a Phone Number
    16. 3Sum Closest
    15. 3Sum
    14. Longest Common Prefix
    13. Roman to Integer
    12. Integer to Roman
    11. Container With Most Water
    10. Regular Expression Matching
    9. Palindrome Number
    8. String to Integer (atoi)
  • 原文地址:https://www.cnblogs.com/xixiaohui/p/12168141.html
Copyright © 2011-2022 走看看