与ember-precompile,ember.js和handlebars.js版本兼容的问题 [英] Version compatible issue with ember-precompile, ember.js and handlebars.js
问题描述
我无法读取我的html中的预编译模板。这是由于与ember.js和handlebars.js的ember-precompile版本兼容的问题。
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.
我的代码如下:
包含以下文件。
<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>
在body标签内读取我编译的模板。
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>
我已经在命令提示符下下载了npm句柄编译器版本:
I have already downloaded npm handlebars compiler version in command prompt as:
npm install handlebars@1.3.0 -g
在控制台中,手柄COMPILER_REVISION将作为4
In console the handlebars COMPILER_REVISION is coming as 4
Handlebars.COMPILER_REVISION -- 4
使用上述版本,我可以使用Handlebars阅读模板作为
With the above versions i can read the templates using Handlebars as
Handlebars.templates['test_temp'];
然后我从下面的软件包中安装了ember-precompile -
Then i installed ember-precompile from the below package -
安装在命令提示符下:
npm install ember-precompile
现在我不能使用Em.TEMPLATE [template_name]读取编译的模板。
Now I am not able to read the compiled templates using Em.TEMPLATE["template_name"].
我已经包含并安装了ember,handlebars和ember-precompile的版本,
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.
推荐答案
我始终没有更新 ember-precompile
的问题。幸运的是,您可以自行更新库。只需转到安装了 ember-precompile
的文件夹(对于我来说,它的全局位于 / usr / local / share / npm / lib / node_modules / ember-precompile
),并替换供应商
文件夹中的库。最新版本使用Ember 1.2.0和Handlebars 1.1.2。只需更换所需的版本。 (您可能需要保留相同的名称,但我不能记得。)
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.)
另外,为什么在页面中包含预编译的Javascript文件?这破坏了预编译的整个目的。
Also, why are you including the precompile Javascript files in your page? That defeats the whole purpose of precompiling.
这篇关于与ember-precompile,ember.js和handlebars.js版本兼容的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!