这是我的网站的设置:
索引.html
<!DOCTYPE html>
<html>
<head>
<script>
var require = {
paths : {
jQuery : "jquery-1.7.2.min"
},
baseUrl: "/scripts"
};
</script>
<title>Javascript RequireJS Example</title>
</head>
<body>
<div id="test"></div>
<script src="scripts/require.js" type="text/javascript" data-main="main.js"></script>
</body>
</html>
hello-wired-spec.js
define({
message: "I haz been wired",
node : "#test",
helloWired: {
create: {
module: 'hello-wired'
},
ready: {
sayHello: [{ $ref : 'node' }, { $ref : "message" }]
}
},
plugins: [
{ module: 'debug', trace: true }
]
});
你好-wired.js
define(["jQuery"], function() {
function HelloWired() {}
HelloWired.prototype = {
sayHello: function(node, message) {
$(node).html("Hello! " + message);
}
};
return HelloWired;
});
main.js
require(["wire!hello-wired-spec", "jQuery"], function (spec) {
console.log(spec);
});
所以我正在使用Require.js
并wire.js
编写一个简单的 IoC 原型网站。我的问题是,当我加载 index.html 页面时,我在浏览器的控制台中看到以下内容:
DEBUG (total: 1ms, context: 0ms / 0ms): Context init
---------------------------------------------------
WIRING: No progress in 5000ms, status:
checkPaths()
logger.error(tag + ': No progress in ' + timeout + 'ms, status:');
---------------------------------------------------
Components that DID NOT finish wiring
plugins[]: created
Object { module= "debug" , trace= true , id= "plugins[]" }
helloWired: created
Object { create={...}, ready={...}, id="helloWired"}
---------------------------------------------------
所以看起来我错过了一些东西,但我不知道在这里做什么。有人可以帮忙吗?
编辑这是Scripts
我网站中的文件夹:
编辑好的我稍微改变了项目结构和HTML页面:
<!DOCTYPE html>
<html>
<head>
<script>
var require = {
paths : {
jquery : "jquery-1.7.2.min",
wire : "wire/wire"
},
baseUrl: "/scripts",
packages: [
{ name: 'wire', location: 'wire', main: 'wire' },
{ name: 'when', location: 'when', main: 'when' },
{ name: 'aop', location: 'aop', main: 'aop' }
]
};
</script>
<title>Javascript RequireJS Example</title>
</head>
<body>
<div id="test"></div>
<script src="scripts/require.js" type="text/javascript" data-main="main.js"></script>
</body>
</html>
现在我之前没有得到任何 404,但我也没有“包”配置部分。在更改 HTML 后,我确实得到了一些 404,但我已经通过将/js
文件放置在预期的位置来修复这些问题。毕竟这一切,我仍然得到同样的错误: