相对路径不起作用RequireJS

时间:2017-05-31 13:59:34

标签: javascript angularjs typescript requirejs relative-path

我正在尝试使用RequireJS在CCSEQ.WebAPI.js文件中包含ExpenseUpload.js。根据{{​​3}} RequireJS的基本URL是html文件中指定的data-main文件夹(在我的情况下为WebResources/js/main)。但是,尽管尝试了各种不同的相对路径组合,但我无法包含CCSEQ.WebAPI.js文件。

我尝试使用/../开始我的相对路径,在配置中指定baseURL,并将我的CCSEQ.WebAPI.js文件移动到文件夹结构中的不同位置,但没有成功。

有人看到我在这里犯的错误吗?

错误

RequireJS Documentation

项目结构

- WebResources
  - js
    - html
      - ExpenseUpload.html
    - lib
      - CCSEQ.WebAPI.js
    - main
      - ExpenseUpload.js

ExpenseUpload.html

<!DOCTYPE html>

<html lang="en" ng-app="expenseUploadApp">
<head>
    <meta charset="utf-8" />
    <title>Expense Upload</title>
    <link rel="icon" href="data:;base64,iVBORwOKGO=" />
    <link href="../css/ExpenseUpload.css" rel="stylesheet" />

</head>
<body ng-controller="DisplayCtrl">
    <h1>Expense Upload</h1>

    <form>

        <label>Month:</label>
        <select ng-model="selectedMonth" ng-options="x for x in months">

        </select> 
        <label>Year:</label>
        <select ng-model="selectedYear" ng-options="y for y in years">
        </select><br/>
        <input type="file" id="csv-file" name="files" />
    </form>

    <script src="../../Scripts/jquery-3.1.1.js"></script>
    <script src="../../Scripts/papaparse.js"></script>
    <script src="../../Scripts/angular.js"></script>
    <script src="../js/modules/ExpenseUploadModule.js"></script>
    <script src="../js/controllers/ExpenseUploadController.js"></script>
    <script src="../../Scripts/require.js" data-main="../js/main/ExpenseUpload.js"></script>
    <!--<img id="loading" src="../../Images/loading.gif" />-->
</body>
</html>

ExpenseUpload.js

requirejs.config({
    bundles: {
        '../lib/CCSEQ.WebAPI.js': ['Model/ExpenseTransaction', 'Model/ExpenseTransactionSet', 'API/ExpenseTransaction', 'API/ExpenseTransactionSet']
    }
});

require(["Model/ExpenseTransaction", "Model/ExpenseTransactionSet", "API/ExpenseTransaction", "API/ExpenseTransactionSet"], function (ExpenseTransactionModel, ExpenseTransactionSetModel, ExpenseTransactionAPI, ExpenseTransactionSetAPI) {
    // Code Here
});

1 个答案:

答案 0 :(得分:0)

根据http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm,它说

  

baseUrl通常设置为与data-main属性中使用的脚本相同的目录。

因此,您的baseUrlmain文件夹,lib处于同一级别。

因此在捆绑包中使用lib/CCSEQ.WebAPI.js

相关问题