0
我在安装与节点NPM车把的问题在安装Handlebars.js,和一般理解如何使用要求()一般。问题与NPM
看来,车把模块根本没有安装。
在WebStorm终端我安装成功地追踪:
NPM安装把手
NPM安装需要
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Todo App: Vanilla JS, Bootstrap, Handlebars</title>
</head>
<body>
<ul class="shoesNav">
<script id="body-template" type="x-handlebars-template">
{{#each this}}
<li class="shoes">{{name}} -- Price: {{price}}</li>
{{/each}}
</script>
</ul>
<script type="text/javascript">
var Handlebars = require('handlebars');
var shoesData = [{name:"Nike", price:199.00 }, {name:"Loafers", price:59.00 }, {name:"Wing Tip", price:259.00 }];
//Get the HTML from the template in the script tag
var theTemplateScript = document.getElementById("body-template").innerHTML;
alert(theTemplateScript);
//Compile the template
var theTemplate = Handlebars.compile(theTemplateScript);
document.getElementsByClassName("shoesNav")[0].appendChild(theTemplate);
//We pass the shoesData object to the compiled handleBars function
// The function will insert all the values from the objects in their respective places in the HTML and returned HTML as a string. Then we use jQuery to append the resulting HTML string into the page
</script>
</body>
</html>
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ ├─┬ [email protected]
│ │ │ │ │ └── [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ └── [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └─┬ [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ └── [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └── [email protected]
└─┬ [email protected]
├── [email protected]
└─┬ [email protected]
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
└── [email protected]
的[需要模块(https://www.npmjs.com/package/require)像你认为它的工作原理是行不通的。 'require'是Node.js内置的一个函数,当你在服务器上运行它时会起作用。如果你想使用Handlebars客户端,你需要添加'