我有4个充满对象的数组:
Array(16) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, … ]
Array(27) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, … ]
Array(21) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, … ]
Array(16) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, … ]
每个对象都包含一些我想向查看者显示的信息:
0: Object { exchange: "NYSE", quote: "JPY", price: "3923.76016", … }
1: Object { exchange: "DEF", quote: "GBP", price: "3924.60972", … }
2: Object { exchange: "FEG", quote: "EUR", price: "3917.31980", … }
3: {…}
exchange: "NEX"
price: "3914.70000"
quote: "USD"
timestamp: "2018-12-31T07:47:11.253Z"
<prototype>: Object { … }
我该如何 1)为数组分配一个唯一值,即数组#1是VTX,数组#2是DEF,因此当我在页面上显示它时,不需要更改股票代码(即,交易所NEX上的VTX为$ 100,而我只需要更改交易所名称和币种/金额)
2)遍历数组,直到迭代器移动到数组中的下一个对象,例如,每2-3秒一次?
我正在React中进行此操作,并将数据传递给了props,但是现在我一直试图解决这个问题。
答案 0 :(得分:0)
1)您可以将所有数组存储在这样的对象上:
const myArrays = [
{
uniqueName: 'VTX',
infos: []
},{
uniqueName: 'DEF',
infos: []
}
]
2)您应该以状态存储索引,并使用componentDidMount中的setInterval对其进行更改
componentDidMount() {
this.timerID = setInterval(
() => this.nextInfo(),
1000
);
}