【发布时间】:2020-02-02 19:03:16
【问题描述】:
我有以下下拉菜单,它们的值是从 MongoDB 重新调整的。
HTML
<form>
<div class="answer1wrap">
<select id="mySelect1">
<option value="void">Choose your answer</option>
{% for row in rows %}
<option value="{{row}}">{{row}}</option>
{% endfor %}
</select>
<select id="mySelect2">
<option value="void">Choose your answer</option>
{% for row in rows %}
<option value="{{row}}">{{row}}</option>
{% endfor %}
</select>
</div>
</form>
<button class="btn btn-default" id="checkbtn" onclick="answers_1();answers_2();" type="button"><span class="glyphicon glyphicon-check"></span> Check answers</button>
JS
<script>
function answers_1() {
var select = document.getElementById("mySelect1");
var answer = select.options[select.selectedIndex].value;
return answer;
}
function answers_2() {
var select = document.getElementById("mySelect2");
var answer = select.options[select.selectedIndex].value;
return answer;
}
</script>
我的目标是使用两个 JS 函数的返回值 (ObjectID),然后使用它们来获取该集合中的特定数据。
我有以下函数,其中key_1 和key_2 是从JS 函数返回的值,但不知何故我无法使其工作。
@app.route("/distance_object", methods=['POST', 'GET'])
def distance_object():
row_object = []
cursor = object_collection.find({}, {"_id": 1})
for document in cursor:
row_object.append(document['_id'])
input_1 = object_collection.find({"_id": ObjectId(key_1)}, {"x_input": 2})
input_2 = object_collection.find({"_id": ObjectId(key_2)}, {"x_input": 2})
return render_template("distance.html", rows=row_object)
【问题讨论】:
标签: javascript python html flask