Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何向Javascript公开新添加的选择选项_Javascript_Python_Jinja2_Bootstrap Modal_Flask Sqlalchemy - Fatal编程技术网

如何向Javascript公开新添加的选择选项

如何向Javascript公开新添加的选择选项,javascript,python,jinja2,bootstrap-modal,flask-sqlalchemy,Javascript,Python,Jinja2,Bootstrap Modal,Flask Sqlalchemy,我花了一段时间在这个问题上,找不到一个对我有意义的答案。我并不是说没有100多个答案会有帮助,我只是还没有找到解决办法 我在jinja模板中有一个select字段,连接到Python/Flask/SQLAlchemy应用程序。如果有什么不同,我用的是Bootstrap5。我才刚刚开始接触Javascript 我的目标是:- 在模板中,单击链接打开Bootstrap5模式-工作正常 在模式表单中输入详细信息并保存详细信息-工作正常 当我返回模板时,新条目将显示为可选条目 选项-工作正常 我还希望选

我花了一段时间在这个问题上,找不到一个对我有意义的答案。我并不是说没有100多个答案会有帮助,我只是还没有找到解决办法

我在jinja模板中有一个select字段,连接到Python/Flask/SQLAlchemy应用程序。如果有什么不同,我用的是Bootstrap5。我才刚刚开始接触Javascript

我的目标是:-

在模板中,单击链接打开Bootstrap5模式-工作正常 在模式表单中输入详细信息并保存详细信息-工作正常 当我返回模板时,新条目将显示为可选条目 选项-工作正常 我还希望选择字段默认为 新添加的选项-不工作该字段保持空白 经过调查,似乎新选项(虽然在select字段中可见)还不可用于Javascript

基于SQLAlchemy QuerySelect字段的select字段的代码:-

HTML金贾

Javascript

我已尝试将值设置为len-1,即在新选项之前添加的选项,效果良好

但是当我通过模式添加新记录时,模板似乎还不知道新记录。因此,即使新添加的选项清楚地显示在列表中,选择字段仍保持空白

我错过了什么


谢谢。

我对python没有把握,但是

   <!--The 'btnaddlocation' button is the Save button on the modal-->
    document.getElementById('btnaddlocation').onclick = function() {
    var len = document.getElementById('individual_birth_location').length;      
     if (eventType = 'birth') { 
         document.getElementById('individual_birth_location').value = len;
     } else if (eventType = "death") {
         <!-- similar code-->
    }
    }
您尝试假设的比较不是比较,而是赋值。 因此,如果要检查eventType是否等于“birth”,javascript将如下所示:

document.getElementById('btnaddlocation').onclick = function() {
var len = document.getElementById('individual_birth_location').length;      
if (eventType === 'birth') { 
    document.getElementById('individual_birth_location').value = len;
} else if (eventType === "death") {
    <!-- similar code-->
}
}

谢谢你的回答,我已经在问题中更正了。不幸的是,我仍然有同样的问题。再次感谢您的回复。
   <!--The 'btnaddlocation' button is the Save button on the modal-->
    document.getElementById('btnaddlocation').onclick = function() {
    var len = document.getElementById('individual_birth_location').length;      
     if (eventType = 'birth') { 
         document.getElementById('individual_birth_location').value = len;
     } else if (eventType = "death") {
         <!-- similar code-->
    }
    }
document.getElementById('btnaddlocation').onclick = function() {
var len = document.getElementById('individual_birth_location').length;      
if (eventType === 'birth') { 
    document.getElementById('individual_birth_location').value = len;
} else if (eventType === "death") {
    <!-- similar code-->
}
}