代码地址 app/helpers/likes_helper.rb
like_label = raw "#{icon} <span>#{label}</span>"
link_to(like_label,"#",:title => title, :rel => "twipsy", 'data-count' => likeable.likes_count,
'data-state' => state,'data-type' => likeable.class,'data-id' => likeable.id,
:class => 'likeable', :onclick => "return App.likeable(this);")
代码地址 app/assets/javascripts/app.coffee
likeable : (el) ->
$el = $(el)
likeable_type = $el.data("type")
likeable_id = $el.data("id")
likes_count = parseInt($el.data("count"))
if $el.data("state") != "liked"
$.ajax
url : "/likes"
type : "POST"
data :
type : likeable_type
id : likeable_id
likes_count += 1
$el.data('count', likes_count)
App.likeableAsLiked(el
不明白 likeable_type = $el.data("type")
这样的代码,在 HTML 中生成了明明是 data-type: xxxx
,那 $el.data("type") 是怎么回事?? data 和 type 怎么能够分开呢??求解