handlebars.js - Handlebars.compile 在页面中不起作用。但是,从控制台工作
问题描述
// 我在 html 页面中有以下代码。我正在尝试这个来学习 Handlebars.compile 功能。
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.7/handlebars.min.js">
</script>
<script>
// compile the template
let template = Handlebars.compile("Hello {{message}}");
// execute the compiled template and print the output to the console
console.log(template({ message: "My friend" }));
</script>
//this outputs in console as - Hello
//But when I test this from console for the same page, like for example
let template2 = Handlebars.compile("Hello {{message}}");
console.log(template2({ message: "My friend" }));
//It outputs - Hello My friend
//I am wondering why same is not working from the page.
解决方案
推荐阅读
- c# - 从多个 OledbConnections 动态填充和附加数据到一个 OleDbDataAdapter
- r - 变量作为 data.table 聚合列表中的名称
- javascript - 简单的 Javascript OOP 混淆
- php - 方法 some_method() 总是返回 false
- swift - 如何使用新的实时数据更新所有注入的对象
- javascript - 为什么我的端点的数据不会在成功的身份验证后显示在浏览器上?
- c - RMS 计算 DC 偏移
- dictionary - __repr__ 和 repr 有什么区别?
- node.js - 在 express js 中使用 flash 消息进行表单验证
- java - Java 日期格式时间戳