2013-04-09 56 views
2
<script> 
     function fun() { 
      console.log("fun was called"); 
      return "fun result"; 
     } 
    </script> 

    <script id="template" type="text/template">    
     test: {{window.fun()}}    
    </script> 

在這個例子中,fun()永遠不會被調用。是否可以調用全球函數?我可以在mustache.js模板中調用全局函數嗎?

+0

看起來像把手是答案。 – citykid 2013-04-09 17:42:17

+0

「我們編寫Handlebars.js的主要動機之一,而不是僅僅使用mustache.js,它允許用戶定義全局幫助程序。」 http://blog.teamtreehouse.com/handlebars-js-part-2-partials-and-helpers – citykid 2013-04-09 22:17:31

回答

0

Handlebars.js是解決方案。

相關問題