我有以下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>
}
正在渲染`scripts'部分和jQuery,但我仍然得到了
未捕获的ReferenceError:未定义SelectionOtherInputHelper
var otherManager = new SelectionOtherInputHelper()
来电时出现错误。我还需要做些什么来正确导入和使用这个类?
答案 0 :(得分:1)
我想你忘了这个模块:
@section scripts
{
<script src="~/Scripts/TypeScript/OtherInput.js"></script>
<script>
var otherManager = new SelectionOtherInputs.SelectionOtherInputHelper();
otherManager.getAllSelectionOthers();
</script>
}