2016-10-04 72 views
0

我想使这个:如何使另一个组件的参数中传递一个组件

<%= 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"] | ");"]} 

是不是因为我不能做到这一点,或者因为我做错了?

回答

1

{:safe, iodata}是凤凰的方式来标记为安全无逃逸像<>&字符,以防止XSS打印字符串。您可以使用Phoenix.HTML.Safe.to_iodata/1{:safe, _}术语转换成可在一个串插使用的iodata

<%= 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)" 
%> 
相关问题