javascript 无法读取未定义的属性“tz” - Ember Moment Timezone

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28531167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 09:07:41  来源:igfitidea点击:

Cannot read property 'tz' of undefined - Ember Moment Timezone

javascriptember.jstimezonemomentjs

提问by Coherent

I have an ember app that I am trying to add moment with time zone into:

我有一个 ember 应用程序,我试图将时区时刻添加到:

{
  "name": "front-end",
  "dependencies": {
    "handlebars": "~1.3.0",
    "jquery": "^1.11.1",
    "ember": "1.8.1",
    "ember-data": "~1.0.0-beta.14.1",
    "ember-resolver": "~0.1.7",
    "loader.js": "stefanpenner/loader.js#1.0.1",
    "ember-cli-shims": "stefanpenner/ember-cli-shims#0.0.3",
    "ember-cli-test-loader": "rwjblue/ember-cli-test-loader#0.0.4",
    "ember-load-initializers": "stefanpenner/ember-load-initializers#0.0.2",
    "ember-qunit": "0.1.8",
    "ember-qunit-notifications": "0.0.4",
    "qunit": "~1.17.1",
    "bootstrap": "~3.3.2",
    "ember-simple-auth": "0.7.3",
    "jquery-autosize": "~1.18.12",
    "moment-timezone": "~0.3.0"
  }
}

I load the js file with this line in my Brocfile.js:

我在 Brocfile.js 中使用这一行加载 js 文件:

app.import('bower_components/moment-timezone/builds/moment-timezone-with-data-2010-2020.min.js');

When I start the ember server I get the following error even before I call moment in any of my custom scripts:

当我启动 ember 服务器时,即使在我的任何自定义脚本中调用 moment 之前,我也会收到以下错误:

 Uncaught TypeError: Cannot read property 'tz' of undefined

Could anyone tell me the proper way to load moment-timezone? Thanks!

谁能告诉我加载时刻时区的正确方法?谢谢!

回答by Andrey Mikhaylov - lolmaus

You need to import Moment before importing Moment Timezone.

在导入 Moment 时区之前,您需要先导入 Moment。

See http://momentjs.com/timezone/docs/

http://momentjs.com/timezone/docs/