【问题标题】:React Native flatlist specific dataReact Native flatlist 特定数据
【发布时间】:2019-09-17 17:20:30
【问题描述】:

我需要来自本地 json 文件的数据仅用于测试目的(在理想的世界中,我将从远程 url 获取数据)这个 json 文件是一个包含 8 个对象的数组,但我需要平面列表来呈现第一个3、我该怎么做?

我的代码:

import extratoData from "./extratoData.json"

export default function Body () {
  const [data, setData] = useState([])

  useEffect(() => {setData(extratoData)}, [])

  return(
   <FlatList 
    data={extratoData} 
    renderItem={({item}) => <ExtratoRenderItem title={item.title} amount={item.amount} date={item.date} time={item.time} cashback={item.cashBack}/>}
    keyExtractor={(item, index) => index.toString()}
   />
)

【问题讨论】:

    标签: json react-native react-native-flatlist


    【解决方案1】:

    您可以只使用Array.prototype.slice() 方法。

      var firstThree = extratoData.slice(0, 3);
    

    【讨论】:

      猜你喜欢
      • 2021-06-29
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 2021-06-05
      • 1970-01-01
      • 2018-04-05
      • 2018-06-04
      相关资源
      最近更新 更多