0
我是Backbone.js的起始者。我有一個模型:如何在backbone.js中的模型的數組屬性中插入新數據?
模型類= TPS
和模型實例名稱= tpsInfo
模型數據如下:
{
"range": "",
"rangeid": "",
"maxrange": "",
"minrange": "",
"q_category_id": "1",
"tpsInput": [
{
"q_id": 1,
"q_text": "Need support for Geographic redundancy (GR)?",
"data_type": "2",
"meta": "NULL",
"answer": "" // should be added here !!!
},
{
"q_id": 2,
"q_text": "Number of Redundant sites",
"data_type": "1",
"meta": "0",
"answer": "" // should be added here !!!
}
]
}
我在模板一種形式,當充滿應增加輸入值回答到模型。模板:
<script type=text/template id="quesTable">
<% for(i=0;i<tpsInput.length;i++) { %>
<tr> <td><%= tpsInput[i].q_text %></td>
<td>
<% if( tpsInput[i].data_type == 0)
{
}
else if(tpsInput[i].data_type == 1)
{
%>
<input type='text' id="<%= tpsInput[i].q_id %>" class='form-control' placeholder='Enter value' >
<% }
else if(tpsInput[i].data_type == 2)
{
%>
<input type=checkbox id="<%= tpsInput[i].q_id %>" >
<% } %>
</td></tr>
<% } %>
</script>
如何形成的輸入值插入到答案屬性出現在model.Kindly幫助裏面tpsInput陣列..
非常感謝米莎這種自我說明的解決方案:)! – Mani