這裏是我的網站設置:不明白爲什麼wire.js未能創建對象
的Index.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-有線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 }
]
});
hello-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
文件放在預期的位置來解決這些問題。這一切後,我仍然得到了同樣的錯誤:
我曾嘗試重新構造這個項目。我將發佈腳本文件夾的更新圖像。但是這並沒有阻止這個錯誤。我也會發布錯誤的圖片。現在,我需要一些睡眠:) – 2012-07-19 22:01:21