javascript 未捕获的 ReferenceError:X 未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6682086/
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-25 21:30:03  来源:igfitidea点击:

Uncaught ReferenceError: X is not defined

javascripthtmlwebosenyo

提问by James West

So I am digging through the WebOS enyo framework and am getting very frustrated. I am currently getting the following error in my log. I have been looking at the samples in the framework and I just can't seem to find where the error is stemming from. It's been over a decade since I have done any HTML or js and what I did back then was very basic stuff. Any help would be appreciated

所以我正在挖掘 WebOS enyo 框架并且感到非常沮丧。我目前在我的日志中收到以下错误。我一直在查看框架中的示例,但似乎无法找到错误的根源。我已经有十多年没有做过任何 HTML 或 js 了,当时我所做的是非常基本的东西。任何帮助,将不胜感激

Uncaught ReferenceError: Learning is not defined, index.html:9

未捕获的 ReferenceError:未定义学习,index.html:9

Here is the very simple application, I am currently just attempting to get elements to appear on screen.

这是一个非常简单的应用程序,我目前只是试图让元素出现在屏幕上。

Index.html

索引.html

<!doctype html />
<html>
<head>
    <title>Learning</title>
    <script src="../../enyo/1.0/framework/enyo.js" type="text/javascript"></script>
</head>
<body>
    <script type="text/javascript">
       new MyApps.Learning().renderInto(document.body);
</script>
</body>
</html>

Learning.js

学习.js

enyo.kind({
    name: "MyApps.Learning",
    kind: enyo.VFlexBox,
    components: [
        { kind: "Scrim",
            layoutKind: "VFlexLayout",
            align: "center",
            pack: "center",
            components: [
                {kind: "SpinnerLarge"}
            ]
        }
    ]
});

depends.js

依赖.js

enyo.depends(
    "source/Learning.js",
    "css/Learning.css"
);

and just for the heck of it the

只是为了它

appinfo.json

应用信息.json

file

文件

{
    "id": "com.myapps.learning",
    "uiRevision": "2",
    "version": "1.0.0",
    "vendor": "kizelli",
    "type": "web",
    "main": "index.html",
    "title": "Learning"
}

采纳答案by diagonalbatman

I think this is a problem in your appinfo.json file...

我认为这是您的 appinfo.json 文件中的问题...

You hold the id as: com.myapps.learning

您将 ID 保持为: com.myapps.learning

Yet you reference it as myapps.learning, try either removing the com.from appinfo.json or adding it to your kind definition and your index.html

然而,您将其引用为 myapps.learning,请尝试com.从 appinfo.json 中删除或将其添加到您的种类定义和您的 index.html

回答by Matt

In my experience, this problem occurs when the path to enyo.js is wrong. I had an older copy of the SDK/emulator, so enyo.js was not found at the path I had copied from the tutorial. Upgrading the SDK fixed it for me, but you can probably ssh into your emulator to find the correct path.

根据我的经验,当 enyo.js 的路径错误时会出现此问题。我有一个旧版本的 SDK/模拟器,所以在我从教程中复制的路径中没有找到 enyo.js。升级 SDK 为我修复了它,但您可能可以 ssh 进入您的模拟器以找到正确的路径。

if enyo is not loaded, it won't be able to created any kinds (MyApps.Learning) you've created.

如果未加载 enyo,它将无法创建您创建的任何种类 (MyApps.Learning)。

I was kind of disappointed that there were no errors logged when enyo was not found or didn't load....

我有点失望的是,当没有找到 enyo 或没有加载时,没有记录任何错误......

回答by Bastian

This usually appears when you got something wrong in your Learning.js. I am not quiet sure, but you could try:

当您在 Learning.js 中出现错误时,通常会出现这种情况。我不确定,但你可以尝试:

enyo.kind({
    name: "MyApps.Learning",
    kind: enyo.VFlexBox,
    components: [
        {kind: "Scrim",
         layoutKind: "VFlexLayout",
         align: "center",
         pack: "center",
         components: [
                {kind: "SpinnerLarge"}
            ]
        }
    ]
});