简体   繁体   English

如何仅使用 json 构建整个表单?

[英]How would I build an entire form using just json?

I was given a little quiz to build out a form in html using only a json file using javascript.我接受了一个小测验,使用 javascript 仅使用 json 文件在 html 中构建一个表格。 Is that even possible just using js?仅使用js就可以吗? Can anyone provide me a link or something to reference on google to accomplish this task?谁能给我一个链接或在谷歌上参考的东西来完成这项任务? I have searched for "json file to html" but havent been able to find anything that could help thus far.我已经搜索了“json 文件到 html”,但到目前为止还没有找到任何可以帮助的东西。 The json file contain a menu of items which can be ordered in quantity so I need to have form elements in there as well so as you can see its not an easy search. json 文件包含一个可以按数量订购的项目菜单,因此我还需要在其中包含表单元素,这样您就可以看到它不是一个容易的搜索。 Any tips or pointers would be great.任何提示或指示都会很棒。 I have attached the json form so you can understand the task better.我附上了 json 表格,以便您更好地理解任务。

{
    "menu": {
        "slice of pizza": "2.00",
        "toppings": {
            "pepperoni": ".25",
            "meatballs": ".35",
            "mushrooms": ".40",
            "olives": ".20"
        },
        "sides": {
            "potato salad": "1.25",
            "hummus": "2.50",
            "caesar salad": "3.50",
            "garden salad": "2.25"
        },
        "drinks": {
            "soda": {
                "small": "1.95",
                "medium": "2.20",
                "large": "2.50"
            },
            "juice": "2.00",
            "water": "1.25"
        }
    }
}

correct me, you are gonna to achieve something like this?纠正我,你会达到这样的目标吗?

<h1>SLice of pizza: 2.00</h1>
<label>toping</label>
<select>
<option>peperoni .25</option>
...
<option>olive .20</option>
</select>

if you do so then all you need to do is looping through the json if has more than one valiue then you generate the select tag and then attach it to your html如果你这样做了,那么你需要做的就是循环通过 json 如果有多个值然后你生成 select 标签,然后将它附加到你的 html

i still dont post any code, i am afraid i catch your question wrong我仍然没有发布任何代码,恐怕我把你的问题弄错了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM