javascript - 表单输入文本从 JSON 数组中获取值
问题描述
我为我的 Web 应用程序制作了一个表单,一些字段的值来自从数据库中的处理表中获取的 JSON 数组。
{"treatment":[
{ "id" : 1, "name" : "Leg Training" },
{ "id" : 2, "name" : "Blood Pressure Control" },
{ "id" : 3, "name" : "MTT" },
{ "id" : 4, "name" : "Radiography" },
{ "id" : 5, "name" : "Doppler Ultrasonography" },
]}
我想为我的表单创建输入文本,而不是选择框,以检查用户编写的单词,并从 JSON 数组中的键名中为用户推荐每个相似的单词。当用户从推荐中选择一个单词时,它会在框中显示该单词,但在值中,它将是 id-value 而不是单词 (name-value),因为表格将发布在不同的表格中,至于现在,它只能使用id作为外键从治疗表中获取数据。
解决方案
From what I can understand about your question, this should get you started if you want to use purely HTML and by using input fields.
<form method="get">
<input name="test" type="text" list="list1" autocomplete="off"/>
<datalist id="list1">
<option value="1">Leg Training</option>
<option value="2">Blood Pressure Control</option>
<option value="3">MTT</option>
<option value="4">Radiography</option>
<option value="5">Doppler Ultrasonography</option>
</datalist>
<input type="submit">
</form>
The Display Text won't really be the name of disease but your users can type the name of the disease to find it from the list.
Let me know if you have any confusion here :)
推荐阅读
- electron - 将电子更新到 6.0.0 后 html2canvas 的大小问题
- google-cloud-platform - 防止 GCP 中的 IAM 升级
- nativescript - 升级到 nativescript 6 后出现 global.process.platform 未定义错误
- sql - 唯一索引的分区列必须是索引键错误的子集
- mysql - MySQL:在单个语句中选择同一字段的奇数和偶数
- python - 如何在列表中搜索字符串并输出包含该字符串的所有值?
- java - 如何在Java中转换二维整数数组中的有序对数组
- c++ - 屏幕分辨率高于 1920x1080 时捕获视频
- python - 给定熊猫数据框突出显示一列
- javascript - 使用 jsonp 获取数据