簡體   English   中英

出現類型錯誤“ array.slice不是函數的問題

[英]Trouble with Type Error "array.slice is not a function

我試圖切片一個數組,其中包含由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>
);
}
}

我知道了,它不需要多余的數據,所以我要做的是

componentWillMount() {
 axios.get('https://api.yelp.com/v3/businesses/search', config)
.then(response => this.setState({ businesses: response.data.businesses 
 }));
}

如果可以的話,我不得不深入研究Json數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM