Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用手柄访问Alpha Vantage API_Javascript_Html_Handlebars.js_Alpha Vantage - Fatal编程技术网

Javascript 使用手柄访问Alpha Vantage API

Javascript 使用手柄访问Alpha Vantage API,javascript,html,handlebars.js,alpha-vantage,Javascript,Html,Handlebars.js,Alpha Vantage,我试图使用handlebar.js访问API中的元数据对象,但在控制台中,我不断收到一个错误,上面写着“Missing Helper:Meta”。我不确定是什么原因导致了这种情况。我们非常感谢您的帮助 <body> <div class="container" id="content"></div> <template id="template"> <div class="info"> {{

我试图使用handlebar.js访问API中的元数据对象,但在控制台中,我不断收到一个错误,上面写着“Missing Helper:Meta”。我不确定是什么原因导致了这种情况。我们非常感谢您的帮助

 <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>

我对Handebar不太熟悉,但你可能会把这个问题归咎于这样一个事实,即关键是带有空格的“元数据”。在把手模板中,您正在调用
{{{metadata}}
,它将Meta视为帮助器的名称,而不是对象键

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);
  });