如何在React中显示数组?

时间:2018-03-11 16:20:58

标签: javascript reactjs

我是React的新手,我有一个csv文件,我使用split(",")方法转换为数组。 现在我尝试使用React将这些数据显示为表/网格但是很难,我该怎么做以及最佳做法是什么?

我的csv看起来像这样:

Option Explicit

Sub sortone()
    Dim Area As Range

    Application.ScreenUpdating = False

    With Range("A1", Range("A" & Rows.Count).End(xlUp))
        .Columns(5).Insert
        .Cells(1, 5).Value = "position"

        For Each Area In .Resize(.Rows.Count - 1).Offset(1).SpecialCells(xlCellTypeConstants).Areas
            With Area
                .Resize(, 6).Sort key1:=.Range("F1"), order1:=1
                .Offset(, 4).FormulaR1C1 = "=RANK(RC[1]," & .Offset(, 5).Resize(, 1).Address(, , xlR1C1) & ",1)"
            End With
        Next Area
    End With

    Application.ScreenUpdating = True
End Sub

编辑:那是我的代码:



restaurant, amount, McDonalds, 3$, StarBucks, 2.5$, Wendy's, 1$




1 个答案:

答案 0 :(得分:0)

render() {
    const {csv, data} = this.state
    return(
    <div> {data.map(item => <div> {item} </div>} </div>
   )
}  

第2版

render() {
const {data} = this.state
var t = data.filter(item => item != "restuarant" || "amount");
var amt;
var rest;
var newVals = t.map(function(item, index) {
  if(index % 2 == 0) rest = item;
  else amt = item;
  if(index % 2 ==0 &&  index > 0){
  return {
    amount: this.amt,
    restaraunt: this.rest,
    key: index,
  }
}
});
 return (
  <div>
   <h1> Restraunts and Amount</h1>
   <div> {newVals.map(item =>  <div> {item.restaraunt} {item.amount} </div> } </div>  
  </div>
 )
}