代码之家  ›  专栏  ›  技术社区  ›  Frank Kong

mobx-react中代理到数组的转换

  •  1
  • Frank Kong  · 技术社区  · 6 年前


    这是我的尝试:

    class ClubListStore {
      @observable userClubList
    
      constructor() {
        this.userClubList = []
      }
    
    
      @action getUserClubs = () => {
        const userContract = new appchain.base.Contract(playerAbi, config.userContract)
        appchain.base.getDefaultAccount().then(sender => {
          userContract.methods.getUserClubsSize(sender).call().then((res) => {
            return res
          }).then((res) => {
              for (let i = 0; i < res; i++) {
                userContract.methods.getUserClubs(sender, i).call().then((clubAddr) => {
                  this.userClubList.push(clubAddr)//push value to array here
                })
              }
            }
          })
        })
      }
    
    
    }
    
    const clubListStore = new ClubListStore()
    
    export default clubListStore
    

    当我console.log数组userClubList时,它将显示为代理。

    Proxy {0: "0xf3fA7DB0Cb79b12ca2081F9f5865f3fd01127FAd", length: 1, Symbol(mobx administration): ObservableArrayAdministration}
    [[Handler]]
    :
    Object
    [[Target]]
    :
    Array(1)
    [[IsRevoked]]
    :
    false
    

    我的问题是:

    谢谢您

    0 回复  |  直到 6 年前