我正在尝试制作一个从 JSON 对象创建动态表单输入的 Angular.js 应用程序。
所以首先,我有一个 JSON 对象(称为字段):
[
{"field_id":209,"form_id":1,"name":"firstname","label":"First Name","type":"text"},
{"field_id":210,"form_id":1,"name":"lastname","label":"Last Name","type":"text"},
{"field_id":211,"form_id":1,"name":"email","label":"Email","type":"text"},
{"field_id":212,"form_id":1,"name":"picture","label":"Picture","type":"file"},
{"field_id":213,"form_id":1,"name":"address","label":"Address","type":"file"},
{"field_id":214,"form_id":1,"name":"password","label":"Password","type":"password"},
{"field_id":215,"form_id":1,"name":"","label":"","type":"submit"}
]
对象键type
是表单的输入类型。见下文:
<p ng-repeat="field in fields">
{{field.name}} : <input type="{{field.type}}" value="{{record.data[field.name]}}" />
</p>
现在这对submit
, text
,password
和字段完全适用。但如果类型是,它会将输入类型设置为。checkbox
radio
file
text
如果我替换{{field.name}}
为{{field.type}}
文本,我可以确认它正在输出file
。
如果我静态更改<input type="{{field.type}}"...
为<input type="file"...
它将正确显示文件输入。
为什么它不允许我将输入类型动态设置为文件?