问题
I cannot read the precompiled templates in my html. It is due to the version compatible issue of ember-precompile with ember.js and handlebars.js.
My code goes like this:
Included the below files.
<script src="../js/libs/jquery-1.10.2.js"></script>
<script src="../js/libs/handlebars-v1.3.0.js"></script>
<script src="../js/libs/ember-1.2.0.js"></script>
<script src="js/precompile.js"></script>
<script src="js/precompile.app.js"></script>
Reading my compiled template inside body tag.
<div id="tempdiv">haii</div>
<script type="text/javascript">
var compiledTemplate = Em.TEMPLATES["precompile"];
var temp_html = compiledTemplate({ name: 'World' });
console.log(temp_html); //Uncaught TypeError: Cannot read property 'push' of undefined
$("#tempdiv").html(temp_html);
</script>
I have already downloaded npm handlebars compiler version in command prompt as:
npm install handlebars@1.3.0 -g
In console the handlebars COMPILER_REVISION is coming as 4
Handlebars.COMPILER_REVISION -- 4
With the above versions i can read the templates using Handlebars as
Handlebars.templates['test_temp'];
Then i installed ember-precompile from the below package -
https://www.npmjs.org/package/ember-precompile
Installed in command prompt as:
npm install ember-precompile
Now I am not able to read the compiled templates using Em.TEMPLATE["template_name"].
There is compatible issue with the versions of ember, handlebars and ember-precompile I have included and installed.
What version of each one matches and can read the compiled templates.
回答1:
I always had problems with ember-precompile not being updated. Fortunately, you can update the libraries yourself. Just go to the folder where ember-precompile is installed (for me, it's globally at /usr/local/share/npm/lib/node_modules/ember-precompile), and replace the libraries in the vendor folder. The latest version uses Ember 1.2.0 and Handlebars 1.1.2. Just replace those with the versions you need. (You might need to keep the same names, but I can't really remember.)
Also, why are you including the precompile Javascript files in your page? That defeats the whole purpose of precompiling.
来源:https://stackoverflow.com/questions/23403577/version-compatible-issue-with-ember-precompile-ember-js-and-handlebars-js