Javascript 从地图数据结构中获取值
当我试图在Javascript 从地图数据结构中获取值,javascript,dictionary,reactjs,iteration,Javascript,Dictionary,Reactjs,Iteration,当我试图在Reactjs代码中打印道具的值时,我得到以下结果: console.log(this.props.rec.get('data')); Map __altered: false __hash: undefined __ownerID: undefined _root: ArrayMapNode entries: Array[8] 0: Array[2] 1: Array[2]
Reactjs
代码中打印道具的值时,我得到以下结果:
console.log(this.props.rec.get('data'));
Map
__altered: false
__hash: undefined
__ownerID: undefined
_root: ArrayMapNode
entries: Array[8]
0: Array[2]
1: Array[2]
2: Array[2]
3: Array[2]
0: "language"
1: "ena"
4: Array[2]
5: Array[2]
0: "owners"
1: List
length: 2
__proto__: Array[0]
6: Array[2]
7: Array[2]
length: 8
__proto__: Array[0]
ownerID: OwnerID
__proto__: Object
size: 8
__proto__: KeyedIterable
条目
是一个函数。如何从该数据中获取“语言”和“所有者”的值
我不太明白这个结构,有人能给我解释一下吗 这似乎是个问题,与反应无关
我相信条目具有映射的所有键值对。您是否知道您似乎正在使用immutable.js?检查它的文档 尝试: 您可以使用
.toJS()
获取更可读的数据版本。e、 g.this.props.rec.get('data').toJS()
然后,您可以执行
this.props.rec.get('data').toJS().owners
来获取owners
,或者使用.getIn()
的语法来检索所需的信息,例如this.props.rec.getIn('data','owners')
我们不会直接获取地图格式的数据,因此需要如下转换和获取数据:
let postData: any = Map(this.props.data).toJS()
Object.keys(postData).map((key) => {
console.log(postData[key]['attribute'])
})
您知道吗,您似乎正在使用immutable.js?检查一下它的文件你能给我们看看你的商店吗structure@Maxx谢谢你的答案正是我需要的。对于“所有者”,它返回一个列表。您能告诉我如何获取该值吗?@Sarah与
语言的值相同-this.props.rec.get('data')。get('owners')
。然后您可以通过索引获取所有者,例如this.props.rec.get('data').get('owners').get(0)
Thank@Geraint,这很有帮助:)
let postData: any = Map(this.props.data).toJS()
Object.keys(postData).map((key) => {
console.log(postData[key]['attribute'])
})