打字稿。未捕获的 ReferenceError:显示未在 HTMLInputElement.onchange 中定义

时间:2021-07-05 13:02:07

标签: javascript dom

我正在尝试开发一个 Web 应用程序,其中输入获取书籍的文本文件并对其进行处理以及流行单词的数量,但发生了以下错误:

未捕获的引用错误:在 HTMLInputElement.onchange 中未定义显示。

请帮帮我!!

type UserId = number;

class User {
  constructor(
    public id: UserId,
  ) {
      
  }
}

const usersIds: UserId[] = [];
const someUser = new User(1 as UserId);
usersIds.push(someUser.id); // <-- Correct
usersIds.push(2); // <-- Need to throw compile error

import * as _ from 'lodash';

function show(input) {
  const file = input.files[0];

  const reader = new FileReader();
  reader.readAsText(file, 'UTF-8');
  reader.onload = () => {
    const res = _.words(reader.result, /[а-яА-ЯёЁa-zA-Z]{4,}/gim);
    const result = _.flow([
      _.countBy,
      _.toPairs,
      _.partial(_.orderBy, _, 1, 'desc'),
      _.partial(_.take, _, 10),
    ]);

    const txt = result(res).map(([word, num]) => `<tr><td>${word}<td>${num}`).join('');
    const out = document.getElementById('out');
    out.insertAdjacentHTML('beforeend', txt);
  };
}

1 个答案:

答案 0 :(得分:1)

javascript 如何连接到您的 HTML?我没有看到任何脚本标签或任何东西。如果您以某种方式加载它,请向我们展示如何加载,以便我们了解错误是否是链接。如果它以某种方式链接,则可能在执行脚本之前调用了 onchange,因此尚未定义 show 函数。