【发布时间】:2016-10-05 21:05:28
【问题描述】:
我有一个输入字段类型存储在数据库中,其位置由用户设置。所以例如名字,文本框1,姓氏文本框2。这个位置可以改变。我想渲染一个视图,显示输入元素在数据库中的位置。这是我从数据库中得到的数据数据库`公式:
[ { FormularID: 187,
CampaignID: 13,
FormLabel: 'Title',
InputType: 'textbox',
InputDetails: '',
InputPosition: 1 },
FormularID: 188,
CampaignID: 13,
FormLabel: 'DATE OF BIRTH',
InputType: 'DATE',
InputDetails: '',
InputPosition: 2 },
{ FormularID: 189,
CampaignID: 13,
FormLabel: 'First Name',
InputType: 'textbox',
InputDetails: '',
InputPosition: 0 } ] } `
Now in my view i have tried this but it doesn't arrange based on the position set.
<% for(var i in templateData.formular){ %>
<% if(templateData.formular[i].InputPosition==i){ %>
<% if(templateData.formular[i].InputType=='textbox'){ %>
<div class="form-group">
<label for="inputEmail3"><%=templateData.formular[i].FormLabel + i %></label>
<input type="text" class="form-control" id="inputEmail3">
</div>
<% } %>
<% if(templateData.formular[i].InputType=='date'){ %>
<div class="form-group">
<label for="inputEmail3" class="col-sm-1 col-form-label"><%=templateData.formular[i].FormLabel%></label>
<input type="date" class="form-control" id="inputEmail3">
</div>
<% } %>
<% } %>
因此,如果用户决定将名字设置为 2,将平铺设置为 1,将出生日期设置为 0。我希望视图按该顺序呈现字段。
【问题讨论】:
标签: javascript node.js ejs