我有@link_to js.coffee助手
@link_to = (body, url, html_options = {}) =>
html_options["href"] = url
@content_tag("a", body, html_options)
@html_options_to_s = (html_options) =>
if $.isPlainObject(html_options)
(" #{key}=\"#{value}\"" for key, value of html_options when typeof value isnt "undefined").join("")
else
""
@content_tag = (tag_name, content, html_options) =>
"<#{tag_name}#{@html_options_to_s html_options}>#{content}</#{tag_name}>"
如何使其适用于具有数据属性的链接?例如:
= link_to "", "#", data: {save_url: "/projects/#{@keyword.get("project_id")}/keywords/#{@keyword.id}"}
输出:
<a href="#" data="[object Object]"></a>