2 回答
TA贡献1801条经验 获得超8个赞
const BookInfo = ({ movie, theater, screenId, date, screeninfo }) => {
const filterScreen = () => {
let filteredSreen = screeninfo.filter((item) => item.id === screenId);
let result = filteredSreen.length!==0 ? filteredSreen[0] :void 0 ;
console.log(result); // {id: "2", screen: "2", layer: "5", time: "13:15", dimension: "2D",} <=line5
console.log(result.id) // error
};
return (
<div className="bookInfo">
<div>{movie}</div>
<div>{theater}</div>
<div>{filterScreen()}</div>
</div>
);
};
实际上,您的过滤条件并非每次都包含在 if 条件中
TA贡献1856条经验 获得超11个赞
请添加条件
const filterScreen = () => {
let filteredSreen = screeninfo.filter((item) => item.id === screenId);
let result = filteredSreen[0];
if (result && result.id) { // condition
console.log(result);
console.log(result.id);
}
};
添加回答
举报