【问题标题】:Trouble with Type Error "array.slice is not a function类型错误“array.slice 不是函数”的问题
【发布时间】: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


    【解决方案1】:

    我明白了,这是它不需要的额外数据,所以我做的是这个

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

    如果你愿意,我必须深入了解 Json 数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-26
      • 2013-04-01
      • 2016-03-06
      • 2018-04-28
      • 2019-02-14
      • 2021-10-02
      • 2021-10-30
      相关资源
      最近更新 更多