问题
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?
回答1:
Yep, use the text plugin - http://requirejs.org/docs/download.html#text
Some extra documentation can be found here - https://github.com/requirejs/text
来源:https://stackoverflow.com/questions/12842798/add-mustache-temple-to-require-in-require-js-amd