我有一個函數maps
和array
並檢查每個記錄的狀態。每個月有一個狀態1,2或3,在if
聲明中檢查。然後這些返回一些CSS來改變一個圖標的顏色。React.js:使用Map時不返回CSS的函數
_infoIconStyle() {
//test array
let monthArr = [
{month:'jan', status: 1},
{month:'feb', status: 2},
{month:'mar', status: ''},
{month:'apr', status: 1},
{month:'may', status: 2},
{month:'jun', status: ''},
{month:'jul', status: 1},
{month:'aug', status: 2},
{month:'sep', status: ''},
{month:'oct', status: 1},
{month:'nov', status: 2},
{month:'dec', status: ''}
]
//
monthArr.map((monthRecord) => {
if(monthRecord.status == 1) {
const infoStyle = {
color: "red"
};
return infoStyle
} else if(monthRecord.status == 2) {
const infoStyle = {
color: "orange"
};
return infoStyle
} else {
const infoStyle = {
color: "green"
};
return infoStyle
}
})
}
我所看到的正是我所預期的console.log沒有map
。但是因爲我加了map
沒有CSS
正在返回。
我一直沒有使用ES6
很長時間,我確定它很簡單。有人可以幫忙..謝謝。
'_infoIconStyle'返回undefined。 'monthArr.map(...)'沒有賦值或返回是一個noop。 –