0

当 Durandal 2.0 出来时,我一直在做一个 Hottowel 项目,所以我自然而然地升级了。它有点搞砸了文件结构,移动require.jsdurandal文件夹到Scripts文件夹等。我最终将durandal文件夹移回文件夹,就像在App原始 Hottowel 模板中一样,并指向.require.jsScriptsindex.cshtml

但突然,我在页面加载时收到这些错误:

GET http://localhost:7153/App/jquery.js 404 (Not Found) require.js:1880
GET http://localhost:7153/App/plugins/history.js 404 (Not Found) require.js:1880
GET http://localhost:7153/App/knockout.js 404 (Not Found) require.js:1880

在加载 require 和启动 durandal 之前,我正在加载捆绑的 jQuery 和淘汰赛(使用 ASP.NET 捆绑):

@Scripts.Render("~/scripts/vendor")
    @if(HttpContext.Current.IsDebuggingEnabled) {
        <script type="text/javascript" src="~/Scripts/require.js" data-main="@Url.Content("~/App/main.js")"></script>
    } else {
        <script type="text/javascript" src="~/App/main-built.js"></script>
    }

知道如何解决吗?我不想不得不回到 Durandal 1.2。

4

1 回答 1

1

Consider where require is trying to find the file. If, for instance, http://localhost:7153/App/jquery.js is causing a 404, then I assume it's because the file isn't in that location.

RequireJS will load a resource based on the baseUrl, if specified, in conjunction with any paths that are set up as part of any require.config() calls.

See if you can find where jQuery is being specified as a dependency to a define'd module, or where it is being require'd. i assume it's just being requested as 'jquery'.

In that case, you're going to need to tell require where jQuery lives. Same for knockout. For the Durandal stuff, you may need to repoint the entire durandal folder to somewhere specific, depending o nwhere you located the files.

your require config call might look something like this:

require.config({
    baseUrl: '/',
    paths: {
        'jquery': 'scripts/jquery',
        'knockout': 'scripts/knockout-debug',
        'durandal': 'scripts/durandal'
    }
});

If possible, check out the Durandal samples for 2.0 and you'll see the require.config() that is used in the samples, and you can compare that to your folder structure.

于 2013-08-21T18:23:19.250 回答