![](/img/trans.png)
[英]Check jQuery Selectors in the Keys of Object to have a Non-Blank Value
[英]How to check if JS object keys have the same value?
這就是我到目前為止所得到的,首先我從 firebase 獲取 JSON,然后 .map() 並將其作為 JSX 返回......它工作得很好,但這是事情......
編輯:當從 firebase 獲取時,它變成了一個 JS 對象。
每個 JS 對象都有一個關鍵時間,如何有條件地檢查一個 JS 對象的關鍵時間是否與另一個 JS 對象的關鍵時間相同?
我基本上只想輸出與 JSX 具有相同時間鍵的 JS 對象,而不是具有相同鍵但值與其他 JSX 的第一個不同的其他 JS 對象......如果這有任何意義......
謝謝
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 });
});
固態硬盤
this.state.orders.map(order => {
return (
<TouchableOpacity
key={order.id}
onPress={() => this.deleteSingleItemHandler(order.id)}
>
<View>
<Text>{order.articleName}</Text>
</View>
<View >
<Text>{order.articlePrice}</Text>
</View>
</TouchableOpacity>
);
})
只需從您的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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.