var CustomerTable = React.createClass({
addEmailButton: function(customerId) {
console.log(customerId);
return (
<button onClick={console.log("clicked", customerId)}>X</button>
)
},
render: function() {
var self = this;
return (
<div>
<table>
<thead>
<tr>
<th>Actions</th>
</tr>
</thead>
<tbody>
{
this.state.customers.map(function(customer, i) {
return (
<tr key={i}>
<td>{self.addEmailButton(customer['id'])}</td>
</tr>
)
})
}
</tbody>
</table>
</div>
)
}
});
Bu bileşen oluşturulduğunda, düğmelerden herhangi birine basmadan, konsol.log çağrısı yürütülür.React bir bileşen oluşturma onClick olayını tetikler?
Sadece bir düğme tıklandığında bir yöntem aramak istiyorum, gerçekten karmaşık bir şey yok.
Neden? Eğer ES2015
ok fonksiyonu
<button onClick={function() { console.log("clicked", customerId) } }>X</button>
Eğer onClick
undefined
geçirerek, console.log()
çünkü döner undefined
kullanmıyorsanız
@Sergio Tapia olabilir geribildirim mi verdin –