作者:252575936_8ea84a | 来源:互联网 | 2023-05-16 10:16
ImusingRequirejstoloadtheJavaScriptinourwebapp.TheissuesisthatImgettinganundefin
I'm using Requirejs
to load the Javascript in our web app. The issues is that I'm getting an undefined
object being passed to a module which, when used in other modules, is instantiated perfectly fine.
我正在使用Requirejs在我们的网络应用程序中加载Javascript。问题是我得到一个未定义的对象被传递给一个模块,当在其他模块中使用时,它被完美地实例化。
OK, here's the setup. My main.js
file which requirejs runs on startup:
好的,这是设置。我的main.js文件,其中requirejs在启动时运行:
require.config({
baseUrl: "/scripts",
paths: {
demographics: "Demographics/demographics",
complaints: "Complaints/complaints",
}
});
require(["templates", "demographics", "complaints", "crossDomain"], function (templates, demographics, complaints) {
"use strict";
console.log("0");
console.log(demographics === undefined);
demographics.View.display();
});
A lot of the config has been stripped to just the core files in this problem.
很多配置都被剥离到这个问题的核心文件中。
Here's Demographics.js
:
这是Demographics.js:
define(["ko", "templates", "complaints", "globals", "underscore"], function (ko, templates, complaints, globals) {
// Stuff removed.
return {
View: view
};
});
and Complaints.js
和Complaints.js
define([
"demographics",
"ko",
"templates",
"complaints",
"visualeffects",
"globals",
"webservice",
"underscore",
"typewatcher",
"imagesloaded"],
function (demographics, ko, templates, complaints, visualeffects, globals, webservice) {
"use strict";
console.log("1");
console.log(demographics === undefined);
return {
View: view
};
});
The problem is this - in Complaints.js
the demographics
parameter passed via the define
config is undefined
. The console log out tells me that "demographics === undefined" is true
.
问题是这个 - 在Complaints.js中,通过define config传递的demographics参数是未定义的。控制台注销告诉我“人口统计数据=== undefined”是真的。
However, when the main.js file executes, the demographics parameter passed to it is not undefined, it is, as expected, an instantiated object.
但是,当main.js文件执行时,传递给它的demographics参数不是未定义的,正如预期的那样,它是一个实例化的对象。
Now I'm stuck since I can't see why in complaints.js
that demographics variable is undefined. Can anyone spot what I'm missing please?
现在我陷入困境,因为我无法在投诉中看到为什么人口统计变量未定义。有人能发现我想念的东西吗?
6 个解决方案