Javascript-如何访问嵌套在其他对象中的对象的属性
在React/Meteor的上下文中,从嵌套Javascript对象中提取信息遇到了一些令人惊讶的困难 我的数据结构如下所示(摘自chrome开发工具:Javascript-如何访问嵌套在其他对象中的对象的属性,javascript,reactjs,meteor,Javascript,Reactjs,Meteor,在React/Meteor的上下文中,从嵌套Javascript对象中提取信息遇到了一些令人惊讶的困难 我的数据结构如下所示(摘自chrome开发工具: Object { id: "138451", name: "Attendant", key: "Taiwan", defaultAnimation: 2, position: Object { latitude:0.5, longitude: -0.14 } 在我的React组件WillReceiveProps中,我看到以下行为 co
Object {
id: "138451",
name: "Attendant",
key: "Taiwan",
defaultAnimation: 2,
position: Object
{
latitude:0.5,
longitude: -0.14
}
在我的React组件WillReceiveProps中,我看到以下行为
componentWillReceiveProps(nextProps){
console.log("its getting props");
console.log(nextProps.markers[0]) // this works
console.log(nextProps.markers[0].position) //so does this
console.log(nextProps.markers[0].position.longitude) //breaks
我也试过设置
var positionObject=nextrops.markers[0]。position
但询问此对象也失败。请突出显示我的Javascript noobish错误
谢谢!什么是返回值nextrops.markers[0]。位置?嗨,Yasemin,这返回>对象{纬度:51.5193,经度:-0.140725}我不明白你为什么不访问nextrops.markers[0]。position.longitudean,你从
nextrops.markers[0]得到了什么.position.longitude
?是否未定义
?您的代码符合javascript。我认为您错过了react中的某些内容。返回值nextProps.markers[0]是什么。position?嗨,Yasemin,这返回>对象{纬度:51.5193,经度:-0.140725}我不明白您为什么不访问nextProps.markers[0].position.longitude和您使用nextrops.markers[0]得到了什么。position.longitude
?它是未定义的吗?
?您的代码符合javascript。我想您错过了react中的某些内容。