我在存储中定义了一个可观察的变量,我尝试进行多次调用并将结果推送到Array。这样做时,我发现定义的数组是代理,因此无法在页面中显示信息。
这是我的尝试:
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
我的问题是:
如何将该代理转换为保存从调用中推入的值的数组?
谢谢