我构建了一个 Food-App,它每天显示不同的 Menue。我使用 Axion 访问本地 JSON 数据并尝试使用 .filter 过滤映射菜单。我的问题是我无法过滤特定的天数。我尝试将 JSON 数据重新排列为与当天匹配的名称,但这不是解决方案。Json 数据如下所示:[ { "Weekday": "Monday", "Dishes": [ { "Name": "Vegtables", "Price": "2,80 €" }, { "Name": "Schnitzel and French Fries", "Price": "3,30 €" }, { "Name": "Pasta", "Price": "3,00 €" }, { "Name": "Strawberry Juice", "Price": "0,95 €" } ] }, { "Weekday": "Tuesday", "Dishes": [ { "Name": "Salad", "Price": "n.A." }, { "Name": "Vegetables", "Price": "2,60 €" }, { "Name": "Mozzarella-Pizza", "Price": "2,00 €" }, ] },] and so on... 我的映射和过滤算法如下所示: class Menu extends Component{ constructor(){ super() this.state={ foodData: [], weekday: "Friday", } } render(){ const todaysfood= this.state.foodData.map(({ Day, Dish}, index) => { return ( <div key={index}> <h2 className="day" >{Day}</h2> {Dish.map((Dish, index2) => { return ( <li key={index2} className="Menu"> {Dish.Name} {Dish.Price} </li> ); })} </div> ); }) const todaysMenu= todaysfood.filter((Day)=>{ return (Day["Gerichte"] === this.currentWeekday) }) return ( <label> {todaysMenu} </label> ) }}有了它,它总是打印出整个星期菜单而不是日菜单。
添加回答
举报
0/150
提交
取消