我猜这个html是对的
<span id="tag_8" data-translations="{"en":"cat"}" class="myTag selected">chat</span>at
# generated with :
# %span.myTag{:id => "tag_" + tag_id.to_s, :'data-translations' => translations(tag_id).to_json}= tag
我正在尝试从 jquery 脚本中读取翻译,但它失败了:
selectedTag = $('#tag-list li span.myTag.selected:first')
console.log 'translations: ' + selectedTag.data("translations", "en")
=> translations: [object Object]
#however
console.log 'translations: ' + selectedTag.data("translations")
=> translations: {"en"=>"cat"}