Mustache js 导致无法加载资源错误

Mustache js causing failed to load resource error

我有以下小胡子 js 模板:

{{#images}}
    <img src="{{.}}" width="10%"/>
{{/images}}

页面加载时控制台出现以下错误:

GET http://localhost/base/url/path/%7B%7B.%7D%7D 404 (Not Found)

是否可以阻止浏览器在绑定之前尝试加载 mustache 模板中的图像源?

我认为您的问题归结为将模板存储在正确的位置,这样浏览器就不会尝试过早呈现它。

<script id="tmplt" type="text/template">
 {{#images}}
   <img src="{{.}}" width="10%"/>
 {{/images}}
</script>

<script>
 Mustache.render($('#tmplt').html(),mymodel);
 ...
</script>