为了账号安全,请及时绑定邮箱和手机立即绑定

URLSearchParams 中的 arrayFormat 等效项

URLSearchParams 中的 arrayFormat 等效项

白衣染霜花 2021-11-25 16:43:47
递归在这里应该可以正常工作:在最基本的情况下,您可以使用id2. 但是,假设getAdjacentCells可能会返回您已经访问过的单元格,除非您能够跟踪已访问过的 ID 并将其传入,否则您最终将无限递归。function setCellState(id, visited) {  if(id === null) {    return;  }  if(visited === undefined) {    visited = new Set();  }  if(visited.has(id)) {    return;  }  visited.add(id);  board[getBoardPosition(id)].opened = true;  // getAdjacentCells() will return either an array of objects similar to the one the function takes as an argument or an integer  let adjacentCells = getAdjacentCells(id);  // if getAdjacentCells(id) returns a number, add a div to the HTML element with that id  if (typeof (adjacentCells) === "number") {        // Removes all other divs, this prevents repetition        $("#" + id).empty()          // Appends an empty div          .append("<div></div>");  } else if (typeof (adjacentCells) === "object") {    Object.values(adjacentCells).forEach(id2 => setCellState(id2, visited));  }我冒昧地更改了方法名称,以便更能代表该方法的实际作用。我还更改了它以从单个单元格的 ID 开始,因为这简化了递归并允许围绕 的行为进行注释getAdjacentCells以提供更好的上下文。
查看完整描述

1 回答

?
白衣非少年

TA贡献1155条经验 获得超0个赞

你不能。这不是URLSearchParams.

如果您需要该功能,请qs改用。


查看完整回答
反对 回复 2021-11-25
  • 1 回答
  • 0 关注
  • 158 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信