单击React JS

时间:2017-12-12 08:09:32

标签: reactjs onclick

我在渲染后使用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>
    )
})}

1 个答案:

答案 0 :(得分:0)

在您的组件中使用这样的方法:

const deleteItem = (index) =>
    this.setState('tours', [].concat(tours).splice(index, 1));