JSON Response:
Bars: [
{
id: "7",
name: "The Trestle Inn",
address: "339 N 11th St",
city: "Philadelphia",
state: "PA",
category: "Dive Bar",
checkIn: [
{
wait: "0.1",
vibe: "0.35",
crowd: "0.5"
}
],
eventname: "0"
},
{
id: "9",
name: "McGillin's Olde Ale House",
address: "1310 Drury Street",
city: "Philadelphia",
state: "PA",
category: "Pub",
checkIn: [
{
wait: "0.1",
vibe: "0.4",
crowd: "0.2"
}
],
eventname: "0"
},
I am using ReactJs, and attempting to iterate through "Bars", pulling data. I can successfully access the first-tier response, such as Name and Address, but I am failing to process the sub-array "checkIn", where I want to pull the values for 'vibe', 'wait', and 'crowd'.
var WebApp = React.createClass({
componentDidMount: function(){
this.loadFavoritesData();
},
render: function(){
return(
<div>
<Favorites favoritesData={this.state.favoritesData} />
<Newsfeed />
</div>
)
}
});
var Favorites = React.createClass({
render: function(){
//console.log(this.props.favoritesData);
var favoriteNodes = this.props.favoritesData.map(function(favorite, index){
var checkInNodes = favorite.checkIn.map(function(data){
//console.log(data.vibe);
return {data}
});
console.log(checkInNodes.vibe);
return(
<Favorite
name={favorite.name}
address={favorite.address}
key={index}
vibe={checkInNodes.vibe}
/>
)
});
return(
<div>
<h2 className="page-header">Favorite Bars</h2>
{favoriteNodes}
</div>
)
}
});
var Favorite = React.createClass({
render: function(){
return(
<div className="favoriteItem">
<h4>{this.props.name}</h4>
<p>{this.props.address}</p>
<p>Vibe: {this.props.vibe}</p>
</div>
)
}
});
I had initially figured I could access it within the first map function within the Favorites component, but when attempting something like the following, I get an undefined result for favorite.checkIn.vibe although if I console.log(favorite.checkIn) I will return the object, which again, I can't seem to dive into
var Favorites = React.createClass({
render: function(){
var favoriteNodes = this.props.favoritesData.map(function(favorite, index){
console.log(favorite.checkIn.vibe);
return(
<Favorite
name={favorite.name}
address={favorite.address}
key={index}
vibe={favorite.checkIn.vibe}
/>
)
});