我想渲染一下:
<%= render MyProj.SnippetView, "doc_ready.html",
state: "DOMContentLoaded",
func: "setTimeout(function(){
#{render(MyProj.SnippetView, "scroll_page.html",
type: nil,
offset: -75,
target: @scrollTo,
duration: nil)}
}, 1)"
%>
但我收到了错误:
protocol String.Chars not implemented for {:safe, [[[[[[[[["" | "var scrollOffset = "], "" | "-75"] | ";\nvar scrollTarget = "], [["" | "$(\"#"] | "imgasEmpresas16"] | "\").offset().top + scrollOffset"] | ";\n$('html, body').animate({scrollTop: scrollTarget"] | ""] | "}, \n "], "" | "1"] | ");"]}
是因为我不能这样做,还是因为我做错了?
答案 0 :(得分:1)
{:safe, iodata}
是Phoenix将标记字符串标记为可安全打印而无需转义<
,>
和&
等字符以防止XSS的方法。您可以将{:safe, _}
字词转换为iodata
,可以使用Phoenix.HTML.Safe.to_iodata/1
在字符串插值中使用:
<%= render MyProj.SnippetView, "doc_ready.html",
state: "DOMContentLoaded",
func: "setTimeout(function(){
#{render(MyProj.SnippetView, "scroll_page.html",
type: nil,
offset: -75,
target: @scrollTo,
duration: nil) |> Phoenix.HTML.Safe.to_iodata}
}, 1)"
%>