代码(在CoffeeScript中):
$shoppingCartItems.on 'click', $('a.data-trash'), ->
if confirm 'Remove this item?'
console.log $this
$.post '/delete-cart-item',
id: $this.attr 'data-cart-id'
.done (e) ->
alert e.message
if e.type is 'success'
$this.remove()
$itemNumber.text e.data.countItems + ' item(s) - ' + e.data.total
$subTotal.text e.data.sub_total
$vat.text e.data.vat
$total.text e.data.total
return
.fail (xhr, status, e) ->
alert xhr.responseText
return
false
预期结果:
$this will be clicked element of $('a.data-trash')
现实:
$this equal to $shoppingCartItems.
问:
如何让$this
等于预期结果?