简体   繁体   English

Console.log不可变JS

[英]Console.log Immutable JS

So I was looking through some data and threw in a 所以我一直在浏览一些数据,并把

console.log(data)

which printed out 打印出来的

List[1]

after drilling down a few times I was able to get to what I wanted but wasn't sure how to log it out...so I have 经过几次钻探后,我能够找到想要的东西,但是不确定如何注销...所以我有

console.log(data.get(0).get('childItems').get(0).get('nestedItems').get(0).get('name'));

This is extremely long. 这太长了。 Is there not a way to drill in with shorter syntax? 没有办法使用更短的语法进行深入研究吗?

Yes. 是。 You can use the .toJS() method. 您可以使用.toJS()方法。

So in your case: console.log( data.toJS() ) 因此,在您的情况下: console.log( data.toJS() )

 const obj = Immutable.fromJS( { name: [ 'a', 'b', 'c' ], } ); const arr = Immutable.fromJS( [ { name: [ 'a', 'b', 'c' ], } ] ); console.log( obj.toJS().name ); // Should return an array console.log( arr.toJS().name ); // Should return undefined console.log( arr.toJS()[ 0 ].name ); // Should return an array 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.min.js"></script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM