-2

在第 16 行 setText 中,它说 TypeError: Cannot read property 'toString' of undefined 并且我不知道如何解决这个问题。同样在第 30 行,最后一个 for 循环说 i 已经定义但我不确定如何定义。

//lists
var teamNames = getColumn("NBA Teams", "Team");
var teamChampionships = getColumn("NBA Teams", "Championship wins");
var teamConference = getColumn("NBA Teams", "Conference");
//filteredList
var filteredNames = [];

onEvent("userButton", "click", function( ) {
  updateScreen();
});
//updates screen to show filtered team names
function updateScreen(){
  var textOutput = "";
  var championship = getColumn("NBA Teams", "Championship wins");
  textOutput = findMatches(championship);
  setText("teamsArea", textOutput);
}
for (var i = 0; i < teamNames.length; i++) {
  if (teamConference == getText("conferenceDropdown") && teamChampionships == getNumber("championshipInput")) {
    appendItem(filteredNames, teamNames[i]);
  }
}

//macthes data input with teams and returns it
//championship (integer) - user inputs numbert of championshops
//matches (string) - name of matching teams based on inputed date
function findMatches(championship) {
  var teamNames = getColumn("NBA Teams", "Team");
  var matches = filteredNames[i];
  for (var i = 0; i < teamNames.length; i++) {
    if (championship == getNumber("championshipInput")) {
      return matches;
    }
  }
}
4

1 回答 1

0

欢迎来到 StackOverFlow :-)

好的,所以您可能想追溯到这两行:

var championship = getColumn("NBA Teams", "Championship wins");
textOutput = findMatches(championship);

'getColumn' 正在返回“未定义”或空数组 [] 或:

textOutput = findMatches(championship); // returns undefined...

我注意到“findMatches”函数没有定义的返回值,如果为假的话。

  function findMatches(championship) {
      var teamNames = getColumn("NBA Teams", "Team");
      var matches = filteredNames[i];
      for (var i = 0; i < teamNames.length; i++) {
          if (championship == getNumber("championshipInput")) {
              return matches;
          }
      }
      // will return undefined, if for loop never returns "matches"...
   }

没有更多关于标记和其余引用函数(如 getColumn、setText 等)的说明。这看起来是一个不错的起点。

至于第 30 行...那是因为您已经在第 18 行定义了一个变量“i”,然后在第 30 行尝试重新定义它...

我建议将“let”用于块和循环“let” ...

于 2021-04-19T03:54:25.877 回答