Использование Handlebars для доступа к Alpha Vantage API - PullRequest
0 голосов
/ 08 марта 2020

Я пытаюсь получить доступ к объекту метаданных в API с помощью Handlebars. js, но в консоли я получаю сообщение об ошибке "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>

Мой 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);
  });
...