在我的文件中找不到任何导致 Uncaught RangeError: 超出最大调用堆栈的递归
Posted
技术标签:
【中文标题】在我的文件中找不到任何导致 Uncaught RangeError: 超出最大调用堆栈的递归【英文标题】:Can't find any recursion in my file that causes Uncaught RangeError: Maximum call stack exceeded 【发布时间】:2018-06-28 22:06:21 【问题描述】:这是我的 html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../resources/js/jquery-3.2.0.min.js"></script>
<script src="../resources/select2-4.0.3/dist/js/select2.min.js"></script>
<link href="../resources/select2-4.0.3/dist/css/select2.min.css" type="text/css" rel="stylesheet">
<script src="../resources/d3/d3.min.js"></script>
<script src="../resources/d3/d3.button.js"></script>
<script src="js/script.js"></script>
<link href="css/style.css" type="text/css" rel="stylesheet">
<title>Database Heat Map</title>
</head>
<body>
<div id="head">
<h1>Database Heat Map</h1>
<div>
<div>
<h3>Schema</h3>
<select class="js-example-basic-single" name="schema" id="schema">
<option></option>
</select>
</div>
<div>
<h3>Table</h3>
<select class="js-example-basic-single" name="table" id="table">
</select>
</div>
</div>
</div>
</body>
</html>
我的选择框的设置方式是第二个选择框的填充取决于第一个选择框的选择。第一个下拉菜单中的每个 Schema 都有自己的一组唯一表。
这是我的 javascript/Jquery:
$(document).ready(function () //Load in json file using d3
getSchema();
$("#schema").change(function()
var e = document.getElementById("schema");
var selectedSchema = e.options[e.selectedIndex].value;
console.log(selectedSchema)
if (selectedSchema != "")
getTable(schema);
)
function getSchema()
$.ajax(
url: "heatmap.py",
dataType: "json",
data: get: "schema",
success: function(results)
console.log(results);
populateSchemaDropDown(results);
,
error: function()
console.log("schema error");
)
function getTable(schema)
$.ajax(
url: "heatmap.py",
dataType: "json",
data: findTables: schema,
success: function(results)
console.log(results);
,
error: function()
console.log("table error")
)
function populateSchemaDropDown(schema)
$('#schema').select2(
placeholder: "--Select One--",
allowClear: true,
data: schema,
dropdownAutoWidth: true
)
function populateTableDropDown(table)
$("#table").select2(
placeholder: "--Select One--",
allowClear: true,
disabled: true
)
第一个下拉框填充得很好,但是每当我单击一个选项时,它会按应有的方式记录选项的名称,但我不断收到来自 jquery 的 Uncaught RangeError: Maximum call stack size exceeded 错误
这里也是python文件(忽略缩进语法,它没有正确粘贴):
def getSchema():
historicalRefreshStats = json.load(open(os.path.join(scriptDir, "historicalRefreshStats.json")))
schemas = []
for server in historicalRefreshStats:
currentServer = unicodedata.normalize('NFKD', server).encode('ascii', 'ignore')
for schema in historicalRefreshStats[currentServer]:
currentSchema = unicodedata.normalize('NFKD', schema).encode('ascii', 'ignore')
schemas.append(currentSchema)
return sorted(list(set(schemas)))
def getTables(schemaToFind):
historicalRefreshStats = json.load(open(os.path.join(scriptDir, "historicalRefreshStats.json")))
tables = []
for server in historicalRefreshStats:
currentServer = unicodedata.normalize('NFKD', server).encode('ascii', 'ignore')
for schema in historicalRefreshStats[currentServer]:
currentSchema = unicodedata.normalize('NFKD', schema).encode('ascii', 'ignore')
if schemaToFind == currentSchema:
for table in historicalRefreshStats[currentServer][currentSchema]:
tables.append(table)
return sorted(list(set(tables)))
form = cgi.FieldStorage()
if "get" in form:
schemas = getSchema()
print "Content-Type: text/json; charset=ISO-8859-1\n"
print json.dumps(schemas)
elif "findTables" in form:
schema = form["findTables"]
tables = getTables(schema)
print "Content-Type: text/json; charset=ISO-8859-1\n"
print json.dumps(tables)
else:
print "Content-Type: text/json; charset=ISO-8859-1\n"
print json.dumps("error")
感谢任何帮助!我不认为它在递归地做任何事情,我检查以确保它不是触发错误的 python 响应。但如果我收到错误,它一定是递归的,对吧?
【问题讨论】:
【参考方案1】:您调用 getTable(schema) 但未定义架构,它应该是 selectedSchema,您也不需要那么多代码,事情可能会更短,“更少的代码 = 更少的问题”
比如更改函数:https://fiddle.jshell.net/____mmc/znqxaa2h/
$("#schema").change(function()
let selectedItem = $('#schema').select2('data')[0]
....
)
还有 ajax 调用,你可以将调用嵌入到 select2 https://select2.org/data-sources/ajax
【讨论】:
您也应该在答案中包含您的代码副本以上是关于在我的文件中找不到任何导致 Uncaught RangeError: 超出最大调用堆栈的递归的主要内容,如果未能解决你的问题,请参考以下文章
我在我的 Github 文件夹中找不到我的 git.exe 文件