我在渲染后使用map来渲染一些Json数据我只想在点击删除按钮时删除父项
{tours.map((item, index) => {
return (
<div className="cart-item" key={index}>
<div className="image">
<img src={"/uploads/thumbs/tour/" + item.image} alt="" />
</div>
<div className="info">
<h2>{item.name}</h2>
<ul><li className="calendar-small-icon">{moment(item.start_date, ["YYYY-MM-DD"]).format('D MMMM')}</li><li className="duration">{item.day_num} დღიანი </li></ul>
</div>
<div className="actions">
<div className="price">{item.price} <span className="lari">₾</span> </div>
<NumericInput min={0} max={100} value={item.number} className="number-input" />
<i className="icon-close delete"></i>
</div>
</div>
)
})}
答案 0 :(得分:0)
在您的组件中使用这样的方法:
const deleteItem = (index) =>
this.setState('tours', [].concat(tours).splice(index, 1));