【发布时间】:2018-08-20 21:32:25
【问题描述】:
我正在尝试对一个数组进行切片,该数组包含由 yelps API 获取的 Json 数据,它给了我一个类型错误消息,说它不是一个函数。我相信它说数组不是使用方法的有效数据类型 .slice() 将 Json 数据作为道具传递到组件中的另一种方法是什么?
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>
);
}
}
【问题讨论】:
标签: javascript reactjs native slice array.prototype.map