私はこれまでRequireJSを使用したことがないので、助けていただければ幸いです。私は次のHTMLを持っています:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript"
data-main="CustomScripts/market-need"
src="CustomScripts/require.js"></script>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
etc...
</body>
</html>
次のJavaScriptをで定義していCustomScripts/market-need.js
ます。
(function(){
requirejs.config({ baseUrl: 'CustomScripts' });
require(['mndataservice'],
function (mndataservice) {
mndataservice.getListData();
});
})();
そして、に保存された次のコードCustomScripts/mndataservice.js
。
define([], function () {
function getListData() {
alert("Hit");
}
return
{
getListData: getListData
};
});
上記を実行するときはいつでも、がの行にmndataservice
ヒットしたときには未定義です。これはある時点で機能しましたが、私と私は自分の人生で犯した誤りを見つけることができません。mndataservice.getListData();
market-need.js