到目前为止,这就是我所得到的,首先我从firebase中获取JSON,然后将其.map()并以JSX的形式返回...并且工作正常,但这就是问题... >
编辑:从firebase中获取时,它成为JS对象。
每个JS对象都有一个关键时间,如何有条件地检查一个JS对象的关键时间是否与另一个JS对象的关键时间相同?
我基本上只想输出对JSX具有相同时间键的JS对象,而不是对其他JSX具有相同键但值不同于其他JSX的其他JS对象。。。 / p>
谢谢
//
// Zusammenfassung:
// Gets the number of frames in the stack trace.
//
// Rückgabewerte:
// The number of frames in the stack trace.
public virtual int FrameCount { get; }
sdsd
axios
.get(`...firebaseio.com/users/${uid}/orders.json`)
.then(response => {
const fetchedOrders = [];
for (let key in response.data) {
fetchedOrders.push({
...response.data[key],
id: key
});
}
this.setState({ orders: fetchedOrders });
});
答案 0 :(得分:0)
只需将值从orders
对象中取出,并在渲染它们之前按时间对其进行排序。这是工作示例:
const fetchedOrders = {"a":{"time":"2018-11-08T11:52:22.668Z"},"b":{"time":"2018-11-08T11:52:28.746Z"},"c":{"time":"2018-11-08T11:52:44.964Z"},"d":{"time":"2018-11-08T11:52:44.964Z"},"e":{"time":"2018-11-08T11:52:52.825Z"},"f":{"time":"2018-11-08T11:52:52.825Z"}};
const orders = Object.values(fetchedOrders)
.sort((order1, order2) => order1.time - order2.time);
// just for showing the result in dom
document.getElementById('result').innerHTML = JSON.stringify(orders, null, 2);
<pre id="result"></pre>