我正在尝试切片一个数组,该数组包含yelps API获取的Json数据,并且它给我一个类型错误消息,说它不是一个函数。我相信它说数组不是使用该方法的有效数据类型.slice()将Json数据作为prop传递给组件的另一种方法是什么?
state = { businesses: [], profileIndex: 0 };
componentWillMount() {
axios.get('https://api.yelp.com/v3/businesses/search', config)
.then(response => this.setState({ businesses: response.data }));
}
upcomingCard = () => {
this.setState({profileIndex: this.state.profileIndex + 1});
}
displayPlace = () => {
const {profileIndex, businesses} = this.state;
{businesses.slice(profileIndex, profileIndex + 1).map(place => {
return (
<SwipeCard
key={place.id}
place={place}
onSwipeOff={this.upcomingCard}
/>
);
})
}}
render() {
console.log(this.state.businesses);
return (
<View style={{flex:1}}>
{this.displayPlace()}
</View>
);
}
}
答案 0 :(得分:0)
我明白了,它是不需要的额外数据,所以我做的就是这个
componentWillMount() {
axios.get('https://api.yelp.com/v3/businesses/search', config)
.then(response => this.setState({ businesses: response.data.businesses
}));
}
如果你愿意的话,我不得不去挖掘Json数据。