访问 Observable 数组的元素
Access elements of an Observable Array
我有一个名为 blockers 的道具,它 returns 一个可观察的对象数组。这些对象包含 'userId.'
我怎样才能返回包含这些用户 ID 的数组?
Computed observables can help with situations like these. Make sure that your component is decorated as a mobx-react
@observer,这样它会自动使 props 可见。
@computed get userIds () {
return this.props.blockers.map(blocker => blocker.userId)
}
我有一个名为 blockers 的道具,它 returns 一个可观察的对象数组。这些对象包含 'userId.'
我怎样才能返回包含这些用户 ID 的数组?
Computed observables can help with situations like these. Make sure that your component is decorated as a mobx-react
@observer,这样它会自动使 props 可见。
@computed get userIds () {
return this.props.blockers.map(blocker => blocker.userId)
}