0

我有以下 TypeScript 模块,为简洁起见删除了不必要的绒毛:

/// <reference path="jquery.d.ts" />
module SelectionOtherInputs {
    export class SelectionOtherInputDescriptor {
        constructor(public selectionId: string, public otherKey: any, public otherInputElementId: string) { }
    }
    export class SelectionOtherInputHelper {

        selectionsWithOther: { [selectionKey: string]: SelectionOtherInputDescriptor; } = {};

        getAllSelectionOthers() {
            $("[" + ATT_SELECTION_OTHER_FOR + "]").each(function () {
                var key = $(this).attr(ATT_DATA_SELECTION_OTHER_KEY);
                var desc = new SelectionOtherInputDescriptor("0", key, $(this).attr("id"));
                this.selectionsWithOther[key] = desc;
            });
        }
    }
}

然后我尝试SelectionOtherInputHelper在一个小的演示页面中使用该类,如下所示:

@section scripts
{
    <script src="~/Scripts/TypeScript/OtherInput.js"></script>
    <script>
        var otherManager = new SelectionOtherInputHelper();
        otherManager.getAllSelectionOthers();
    </script>
}

正在渲染“脚本”部分和 jQuery,但我仍然得到一个

未捕获的 ReferenceError:未定义 SelectionOtherInputHelper

var otherManager = new SelectionOtherInputHelper()通话出错。我还必须做什么才能正确导入和使用这个类?

4

1 回答 1

1

我想你忘记了模块:

@section scripts
{
    <script src="~/Scripts/TypeScript/OtherInput.js"></script>
    <script>
        var otherManager = new SelectionOtherInputs.SelectionOtherInputHelper();
        otherManager.getAllSelectionOthers();
    </script>
}
于 2013-03-05T11:27:09.997 回答