index.html:
<script id="test" type="text/html">
{{each data as value index}}
<li>{{index}} - {{value.user}}</li>
{{/each}}
</script>
app.js:
require.config({
baseUrl: "./js",
paths:{
"add": "./work/add",
"jquery": "./lib/jquery-2.0.3.min",
"each": "./work/each",
"text":"./lib/text",
"template":"./lib/template",
"math":"./app/math",
"api":"./app/api"
}
});
require(["add","jquery","each","template","text!table.html","math","api"],function(add,$,each,template,moban,math,api){
console.log(add.add(20,19));
console.log(each.each([1,2,3,4,5]));
console.log(moban);
$("-sharpcontent").html(moban);
console.log(math.minus(20,9));
console.log(math.product(2,6));
api.getUser().then(function(user){
console.log(user)
});
var data = [
{
name: ""
},
{
name: ""
},
{
name: ""
},
{
name: ""
},
];
var html = template("test", data);
document.getElementById("content").innerHTML = html;
});
the file path is as follows:
I would like to ask why the template was not rendered when I introduced template.js in require.js. Html is undefined?. And now that I can introduce html files, can I also introduce tpl files?