如何设置“ENV”变量在EmberJS? [英] How do I set an "ENV" variable in EmberJS?

查看:127
本文介绍了如何设置“ENV”变量在EmberJS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新到EmberJS 0.9.8.1后,我现在得到两个警告:

 警告:默认情况下,计算的属性很快就可以缓存。要在您的应用程序中启用
,请设置ENV.CP_DEFAULT_CACHEABLE = true。

And:

 code>警告:{{view}}助手影响模板的方式即将更改。 
... SNIP ...通过设置ENV.VIEW_PRESERVES_CONTEXT = true。

这可能看起来像一个愚蠢的问题,但是如何设置这些ENV变量?我已经尝试了几种不同的方式,没有一个可以使警告消息消失,我的应用程序也没有任何内容。这是否意味着我很清楚?还是意味着我没有正确设置ENV变量?


  1. window.ENV 不存在,所以在字面上做ENV.CP_DEFAULT_CACHEABLE = true不起作用

  2. Ember.ENV 存在,但是是一个空对象,没有Ember.ENV。设置方法。所以我试着做Ember.ENV.CP_DEFAULT_CACHEABLE = true。这是设置ENV的正确方法吗?但是,它并没有影响Ember.CP_DEFAULT_CACHEABLE,所以似乎不正确。

  3. Ember.CP_DEFAULT_CACHEABLE 存在,所以我试过做了Ember。 CP_DEFAULT_CACHEABLE = true,但这并不影响Ember.ENV.CP_DEFAULT_CACHEABLE。

  4. 我也尝试过使用Ember.set('CP_DEFAULT_CACHEABLE',true)。

哪些(如果有的话)是正确的方式来回应这些警告?当你根据他们的请求设置东西时,他们不会离开吗?警告应该更好地记录这些信息,或提供您设置的反馈。

解决方案

您必须确保 ENV 变量被设置,在Ember.js被加载之前(在 ember-metal / lib / core.js ),请参见 http://jsfiddle.net/pangratz666/jweyf/

 <!doctype html> 
< body>
< script type =text / javascript>
ENV = {
CP_DEFAULT_CACHEABLE:true,
VIEW_PRESERVES_CONTEXT:true
};
< / script>
< script src =http://code.jquery.com/jquery-1.7.2.js>< / script>
< script src =https://github.com/downloads/emberjs/ember.js/ember-0.9.8.1.js>< / script>
...
< / body>


After updating to EmberJS 0.9.8.1 I now get two warnings:

WARNING: Computed properties will soon be cacheable by default. To enable this
in your app, set `ENV.CP_DEFAULT_CACHEABLE = true`. 

And:

WARNING: The way that the {{view}} helper affects templates is about to change.
...SNIP...  by setting `ENV.VIEW_PRESERVES_CONTEXT = true`.

This may seem like a stupid question, but how do I set these ENV variables? I've tried setting them a few different ways, and none make the WARNING message go away, and nothing in my App breaks either. Does that mean I'm in the clear? Or does it mean I'm not setting the ENV variables correctly?

  1. window.ENV does not exist, so literally doing 'ENV.CP_DEFAULT_CACHEABLE = true' doesn't work
  2. Ember.ENV exists, but is an empty object, and has no Ember.ENV.set method. So I tried doing Ember.ENV.CP_DEFAULT_CACHEABLE = true. Is this the correct way to set an ENV? It, however has no effect on Ember.CP_DEFAULT_CACHEABLE, so that doesn't seem right.
  3. Ember.CP_DEFAULT_CACHEABLE exists, so I've tried doing Ember.CP_DEFAULT_CACHEABLE = true, but this has no effect on Ember.ENV.CP_DEFAULT_CACHEABLE.
  4. I've also tried doing Ember.set('CP_DEFAULT_CACHEABLE', true).

Which (if any) of these is the right way to respond to these warnings? Do they not just do away when you set things based on their pleas? The warnings should probably document this better, or provide feedback that you set them.

解决方案

You have to make sure that the ENV variable is set, before Ember.js is loaded (defined in ember-metal/lib/core.js), see http://jsfiddle.net/pangratz666/jweyf/:

<!doctype html>
<body>
    <script type="text/javascript" >
        ENV = {
            CP_DEFAULT_CACHEABLE: true,
            VIEW_PRESERVES_CONTEXT: true
        };
    </script>
    <script src="http://code.jquery.com/jquery-1.7.2.js"></script>
    <script src="https://github.com/downloads/emberjs/ember.js/ember-0.9.8.1.js"></script>
    ...
</body>

这篇关于如何设置“ENV”变量在EmberJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆