0

我有一个带有 json 数据的表单生成器

{ "10" : { "custom" : null,
      "custom2" : null,
      "label" : "Sublimacja",
      "max" : "",
      "min" : "",
      "required" : "0",
      "tooltip" : "field7",
      "type" : "dropdown",
      "validation" : "",
      "value" : "Sublimacja 205g"
    },
  "11" : { "custom" : null,
      "custom2" : null,
      "label" : "Druk+UV",
      "max" : "",
      "min" : "",
      "required" : "0",
      "tooltip" : "field8",
      "type" : "dropdown",
      "validation" : "",
      "value" : "Kalka"
    },
  "12" : { "custom" : null,
      "custom2" : null,
      "label" : "Rodzaj+wyko%C5%84czenia",
      "max" : "",
      "min" : "",
      "required" : "0",
      "tooltip" : "field9",
      "type" : "dropdown",
      "validation" : "",
      "value" : "Cięcie do wymiaru"
    },
  "13" : { "custom" : null,
      "custom2" : null,
      "label" : "Rodzaj+wysy%C5%82ki",
      "max" : "",
      "min" : "",
      "required" : "0",
      "tooltip" : "field10",
      "type" : "dropdown",
      "validation" : "",
      "value" : "UPS Standard"
    },
  "14" : { "custom" : null,
      "custom2" : null,
      "label" : "Adres+wysy%C5%82ki",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field11",
      "type" : "para",
      "validation" : "",
      "value" : ""
    },
  "15" : { "custom" : null,
      "custom2" : null,
      "label" : "Uwagi+dodatkowe",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field12",
      "type" : "para",
      "validation" : "",
      "value" : ""
    },
  "16" : { "custom" : null,
      "custom2" : null,
      "label" : "divider",
      "max" : null,
      "min" : null,
      "required" : null,
      "tooltip" : null,
      "type" : "divider",
      "validation" : "divider",
      "value" : "Plik 1"
    },
  "17" : { "custom" : null,
      "custom2" : null,
      "label" : "Nazwa+pliku+1",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field14",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "18" : { "custom" : null,
      "custom2" : null,
      "label" : "Ilo%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field15",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "19" : { "custom" : null,
      "custom2" : null,
      "label" : "Wysoko%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field16",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "2" : { "custom" : null,
      "custom2" : null,
      "label" : "",
      "max" : null,
      "min" : null,
      "required" : null,
      "tooltip" : null,
      "type" : null,
      "validation" : null,
      "value" : ""
    },
  "20" : { "custom" : null,
      "custom2" : null,
      "label" : "Szeroko%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field17",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "21" : { "custom" : null,
      "custom2" : null,
      "label" : "divider",
      "max" : null,
      "min" : null,
      "required" : null,
      "tooltip" : null,
      "type" : "divider",
      "validation" : "divider",
      "value" : "Plik 2"
    },
  "22" : { "custom" : null,
      "custom2" : null,
      "label" : "Nazwa+Pliku+2",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field19",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "23" : { "custom" : null,
      "custom2" : null,
      "label" : "Ilo%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field20",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "24" : { "custom" : null,
      "custom2" : null,
      "label" : "Szeroko%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field21",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "25" : { "custom" : null,
      "custom2" : null,
      "label" : "Wysoko%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field22",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "26" : { "custom" : null,
      "custom2" : null,
      "label" : "divider",
      "max" : null,
      "min" : null,
      "required" : null,
      "tooltip" : null,
      "type" : "divider",
      "validation" : "divider",
      "value" : "Plik 3"
    },
  "27" : { "custom" : null,
      "custom2" : null,
      "label" : "Nazwa+Pliku+3",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field24",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "28" : { "custom" : null,
      "custom2" : null,
      "label" : "Ilo%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field25",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "29" : { "custom" : null,
      "custom2" : null,
      "label" : "Szeroko%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field26",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "3" : { "custom" : null,
      "custom2" : null,
      "label" : "Nazwa+Firmy",
      "max" : "60",
      "min" : "0",
      "required" : "1",
      "tooltip" : "field0",
      "type" : "text",
      "validation" : "",
      "value" : "fdfdf"
    },
  "30" : { "custom" : null,
      "custom2" : null,
      "label" : "Wysoko%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field27",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "31" : { "custom" : null,
      "custom2" : null,
      "label" : "divider",
      "max" : null,
      "min" : null,
      "required" : null,
      "tooltip" : null,
      "type" : "divider",
      "validation" : "divider",
      "value" : "Plik 4"
    },
  "32" : { "custom" : null,
      "custom2" : null,
      "label" : "Nazwa+Pliku+4",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field29",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "33" : { "custom" : null,
      "custom2" : null,
      "label" : "Ilo%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field30",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "34" : { "custom" : null,
      "custom2" : null,
      "label" : "Szeroko%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field31",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "35" : { "custom" : null,
      "custom2" : null,
      "label" : "Wysoko%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field32",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "36" : { "custom" : null,
      "custom2" : null,
      "label" : "divider",
      "max" : null,
      "min" : null,
      "required" : null,
      "tooltip" : null,
      "type" : "divider",
      "validation" : "divider",
      "value" : "Plik 5"
    },
  "37" : { "custom" : null,
      "custom2" : null,
      "label" : "Nazwa+Pliku+5",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field34",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "38" : { "custom" : null,
      "custom2" : null,
      "label" : "Ilo%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field35",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "39" : { "custom" : null,
      "custom2" : null,
      "label" : "Szeroko%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field36",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "4" : { "custom" : null,
      "custom2" : null,
      "label" : "NIP",
      "max" : "10",
      "min" : "10",
      "required" : "0",
      "tooltip" : "field1",
      "type" : "text",
      "validation" : "integers",
      "value" : "1234567890"
    },
  "40" : { "custom" : null,
      "custom2" : null,
      "label" : "Wysoko%C5%9B%C4%87",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field37",
      "type" : "text",
      "validation" : "",
      "value" : ""
    },
  "41" : { "custom" : null,
      "custom2" : null,
      "label" : "Plik",
      "max" : "",
      "min" : "",
      "required" : "0",
      "tooltip" : "field38",
      "type" : "upload",
      "validation" : "file",
      "value" : "0"
    },
  "42" : { "custom" : null,
      "custom2" : null,
      "label" : "title",
      "max" : null,
      "min" : null,
      "required" : null,
      "tooltip" : null,
      "type" : null,
      "validation" : null,
      "value" : "Zamówienie"
    },
  "5" : { "custom" : null,
      "custom2" : null,
      "label" : "Imi%C4%99",
      "max" : "60",
      "min" : "0",
      "required" : "1",
      "tooltip" : "field2",
      "type" : "text",
      "validation" : "",
      "value" : "dfdf"
    },
  "6" : { "custom" : null,
      "custom2" : null,
      "label" : "Nazwisko",
      "max" : "60",
      "min" : "0",
      "required" : "1",
      "tooltip" : "field3",
      "type" : "text",
      "validation" : "",
      "value" : "dfdff"
    },
  "7" : { "custom" : "autoreply",
      "custom2" : "replyto",
      "label" : "Email",
      "max" : "",
      "min" : "",
      "required" : "1",
      "tooltip" : "field4",
      "type" : "email",
      "validation" : "email",
      "value" : "kasper@dolczewski.eu"
    },
  "8" : { "custom" : null,
      "custom2" : null,
      "label" : "Rodzaj+zam%C3%B3wienia",
      "max" : "",
      "min" : "",
      "required" : "0",
      "tooltip" : "field5",
      "type" : "dropdown",
      "validation" : "",
      "value" : "Druk sublimacyjny transferowy"
    },
  "9" : { "custom" : null,
      "custom2" : null,
      "label" : "Inne",
      "max" : "60",
      "min" : "0",
      "required" : "0",
      "tooltip" : "field6",
      "type" : "text",
      "validation" : "",
      "value" : ""
    }
}

以及一个输入文件名的表单

<input type="text" name="Nazwa Firmy_text__1_0_60_field0" ng-style="{width: el.wid}" style="width: 100%;">
<span class="inst ng-binding" ng-style="{ fontSize: con[0].ifs+"px", color: con[0].ifc }" style=""></span>

使用 jquery 或某些插件将值设置为表单的最简单方法是什么,因为每个字段的名称是根据输入的 json 数据动态生成的,所以有时它可以是 name_fieldtyoe_max_min 有时没有 min 和 max

有没有办法检查字段的名称,将其与 json 数据进行比较,然后设置值?

4

1 回答 1

0

如果您只知道部分名称,您可以使用以下方式设置输入字段的值

$('input[name^="name_fieldtyoe"]').val('This is value');

上面的行将为名称以 开头的输入字段设置值name_fieldtyoe

有关更多信息,请参阅jQuery 文档

于 2013-08-26T12:20:12.870 回答