代码之家  ›  专栏  ›  技术社区  ›  Kadeo13

在我的文件中找不到导致未捕获范围错误的任何递归:超出了最大调用堆栈

  •  0
  • Kadeo13  · 技术社区  · 8 年前

    这是我的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>
    

    设置“我的选择框”的方式是,根据第一个选择框中选择的内容填充第二个选择框。第一个下拉列表中的每个架构都有自己的唯一表集。

    下面是我的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
        })
    }
    

    第一个下拉框填充得很好,但每当我单击一个选项时,它都会像预期的那样记录该选项的名称,但我总是得到一个未捕获的RangeError:最大调用堆栈大小超出jquery的错误

    这也是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 回复  |  直到 8 年前
        1
  •  2
  •   Marcell Monteiro Cruz    8 年前

    您正在调用getTable(schema),但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