首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在mobx-react中将代理转换为数组

如何在mobx-react中将代理转换为数组
EN

Stack Overflow用户
提问于 2018-11-22 11:04:39
回答 1查看 3.1K关注 0票数 3

我在存储中定义了一个可观察变量,并尝试进行多次调用并将结果推送到Array。当我这样做的时候,我发现我定义的数组是一个代理,所以我不能在我的页面中显示信息。

这是我的尝试:

代码语言:javascript
复制
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

当我对阵列userClubList执行console.log操作时,它显示为代理。

代码语言:javascript
复制
Proxy {0: "0xf3fA7DB0Cb79b12ca2081F9f5865f3fd01127FAd", length: 1, Symbol(mobx administration): ObservableArrayAdministration}
[[Handler]]
:
Object
[[Target]]
:
Array(1)
[[IsRevoked]]
:
false

我的问题是:

如何将此代理转换为保存我从调用中推入的值的数组?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2020-11-24 04:31:49

使用console.log(toJS(userClubList))

https://mobx.js.org/api.html#tojs

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53423288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档