2016-03-03 89 views
0

我得到一個錯誤的手把沒有定義把手錯誤:「把手」沒有定義

app/components/chart-container/chart-container.js 
    15 |  var theTemplate = Handlebars.compile(chartContainerTemplate); 
           ^'Handlebars' is not defined. 

這是整個文件,其中車把被假設是沒有定義

'use strict'; 

var APP = window.APP = window.APP || {}; 

APP.chartContainer = (function() { 

    var bindEventsToUI = function() { 

     $.getJSON('maindata.json', function(data) { 
      var setData = localStorage.setItem('jsonData', JSON.stringify(data)); 
      // console.log('data', localStorage.getItem('jsonData')); 
     }); 

     var chartContainerTemplate = $(".chart-container").html(); 
     var theTemplate = Handlebars.compile(chartContainerTemplate); 

     var getData = localStorage.getItem('jsonData'); 

     var theCompiledHtml = theTemplate(getData); 

     console.log(theTemplate); 

     $(document.body).append(theCompiledHtml); 
    }; 

    var init = function (element) { 
     console.log('APP.chartContainer'); 
     bindEventsToUI(); 
    }; 

    /** 
    * interfaces to public functions 
    */ 
    return { 
     init: init 
    }; 

}()); 

和在default.hbs我有這個身體內的標記

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
<script>window.jQuery || document.write('<script src="assets/scripts/vendor/jquery-1.11.3.min.js"><\/script>')</script> 
<script src="https://cdn.jsdelivr.net/handlebarsjs/4.0.5/handlebars.min.js"></script> 

我錯過了什麼?

+0

'把手=要求( 「把手」);'? – cat

+1

由於APP.chartContainer是一個立即調用的函數,你確定在下載完handlebars後它會被觸發嗎?它是在'jQuery(函數($){...}'? – Quantastical

回答

0

等待下載的所有資源之前啓動您的模板

<script> 
    $(document).ready(function() { 
     // launch your function here 
    }); 
</script>