简体   繁体   English

如何获取json标题

[英]how to get json title

I am having issue with getting title of the schema element in JSON form, so far I have: 我在以JSON格式获取schema元素的标题时遇到问题,到目前为止,我有:

<script type="text/javascript">
      $(window).load(function() {
        $("#thisForm2").validationEngine('attach', {
          onValidationComplete: function(form, status) {
            if (status === true) {
              return true;
            }
          },
        });
        $("#thisForm2").validationEngine({showArrowOnRadioAndCheckbox: true});
      });
      $(function() {


        $('form#thisForm2').jsonForm(
{
          "schema": {
            "adminName": {
              "type": "string",
              "title": "Admin Name"
            },
            "adminEmail": {
              "type": "string",
              "title": "Admin Primary E-mail"
            },
            "size": {
              "type": "array",
              "title": "Size",
              "enum": ["1-100", "100-1K", "1K-10K", "10K+"],
            },
          },
          "form": [
            {
             "key": "adminName",
             "fieldHtmlClass": "form-control validate[minSize[2]]",
            },
            {
             "key": "adminEmail",
             "fieldHtmlClass": "form-control validate[minSize[2]]",
            },
            {
              "key": "size",
              "fieldHtmlClass": "form-control dropDownPrepend validate[minSize[2]]"
            },
          ]
        });

      });
    </script>

In backend, when I use Map<String, String> allRequestParams , I am able to get key/value pair for JSON form, like {adminName=Godzilla, adminEmail=abc@abc.com, size=1K-10K} 在后端,当我使用Map<String, String> allRequestParams ,我能够获取JSON形式的键/值对,例如{adminName=Godzilla, adminEmail=abc@abc.com, size=1K-10K}

So the question is: "How do I get title of the element in back-end?" 所以问题是:“如何在后端获取元素的标题?” By title I mean this: 按标题,我的意思是:

"title": "Admin Name"

Tried to copy title from schema part to form part of JSON, but it seems not working. 试图从模式部分复制标题以形成JSON的一部分,但似乎不起作用。 Maybe I can do some javascript and parse it? 也许我可以做一些JavaScript并解析它? I am new to JSON so I might not know obvious things, any advice is greatly appreciated. 我是JSON的新手,所以我可能不知道明显的事情,任何建议都将不胜感激。 Thanks. 谢谢。

If you would like using Jquery, can try something like this, 如果您想使用Jquery,可以尝试类似的方法,

var titles = [];
$.each(schema[0].adminName, function(index, item){
   titles.push(item.title);
})

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

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