我正在尝试使用 Handlebars.js 访问 API 中的元数据对象,但在控制台中我不断收到错误消息“缺少帮助程序:元”。我不确定是什么原因造成的,感谢您的帮助。
<body>
<div class="container" id="content"></div>
<template id="template">
<div class="info">
{{Meta Data}}
</div>
</template>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.1.2/handlebars.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="index.js"></script>
</body>
</html>
我的 JS 文件:
const content = document.getElementById('content');
const template = document.getElementById('template').innerHTML;
const info = document.querySelector('.info');
function render(context) {
let compiled = Handlebars.compile(template);
template.innerHTML = compiled(context);
}
$.ajax({
url:
'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo',
method: 'GET'
})
.done(function(stonk) {
console.log(stonk);
content.innerHTML = render(template, { info: stonk });
})
.fail(function(error) {
console.error('Something went wrong', error);
});