我在redux动作中从firebase存储中获取了JSON对象。 我将JSON对象存储在关联数组中。 当我尝试执行this.props.expenses时,我取回数组。
但是我无法在JSX中映射数组?
import { SHOW_EXPENSE } from './types';
import database from '../config/firebase';
export const showExpenses = () => dispatch => {
const expenses = [];
database.ref()
.once('value')
.then((snapshot) => {
snapshot.forEach((childSnapshot) => {
expenses.push({
id: childSnapshot.key,
...childSnapshot.val()
})
});
});
console.log(expenses);
dispatch({
type: SHOW_EXPENSE,
expenses : expenses
})
return expenses;
};
这是我的console.log(expenses);
0: {id: "-LUumVQzeXBN8iK81EVO", expense_amount: "500", expense_name:
"bike service"}
1: {id: "-LUumeeCeYIdd2G4Pz5K", expense_amount: "1500",
expense_name: "tire change"}
length: 2__proto__:
Array(0)
当我尝试映射this.props.expenses时,它什么也不返回。
{this.props.expenses.map( data =>
{data.expense_amount}
{data.expense_name}
});