在require.js AMD中添加胡子寺庙到require [英] add mustache temple to require in require.js AMD

查看:62
本文介绍了在require.js AMD中添加胡子寺庙到require的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 js 中,您可以在定义模块时在 require 部分加载 html 模板.例如:

模板文件:test.html

在模块中

定义([模板/测试"],功能() {//.. 其余代码..});

但是这在获取文件名附加有 .js 扩展名的文件时会引发错误.有什么办法可以在定义块中包含模板吗?

解决方案

是的,使用文本插件 - http://requirejs.org/docs/download.html#text

可以在这里找到一些额外的文档 - https://github.com/requirejs/text

In js you can load a html template in the require part while defining a module. For example:

template file : test.html

<script id="test" type="text/template">
 <div class="q-header-holder">
  <h1> {{ quizName }}</h1>
  <a href="{{ instructionLinks }}" class="q-instruction-btn">Instructions</a>
 </div>
</script>

in module

define(
 ["template/test"],
 function() {
  //.. rest of code ..
 }
);

But this throws error while fetching the file the filename appended with .js extension. Is there any way to include the template in the define block?

解决方案

Yep, use the text plugin - http://requirejs.org/docs/download.html#text

Some extra documentation can be found here - https://github.com/requirejs/text

这篇关于在require.js AMD中添加胡子寺庙到require的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆