0
在下面的示例中,如果我添加了多个guest虚拟机,然后删除了guest虚拟机,则guest虚拟机表将消失,即使Guest []不为空也不会再次出现。在这里或我的代码中是否有{^ {if}}错误? (我正在使用提交34)可能与{^ {if}}的jsviews错误
<div id="frm-reg"></div>
<script id='jsr-registration' type='text/x-jsrender'>
<p><button id="btn-addGuest">Add Guest</button></p>
{^{if Guests.length}}
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th></th>
</tr>
{^{for Guests}}
<tr>
<td><input data-link="FirstName" type="text" /></td>
<td><input data-link="LastName" type="text" /></td>
<td><input data-link="Age" type="text" /></td>
<td><button class="btn-remove">Remove</button></td>
</tr>
{{/for}}
</table>
{{/if}}
</script>
<script>
var model={"CampID":3,"FirstName":"a","LastName":"b","Guests":[]};
$.templates({regTmpl: "#jsr-registration"});
$.link.regTmpl("#frm-reg", model)
.on("click", ".btn-remove", function()
{
$.observable(model.Guests).remove($.view(this).index, 1);
return false;
});
$("#btn-addGuest").click(function()
{
$.observable(model.Guests).insert(model.Guests.length, {FirstName:"", LastName:"", Age:""});
return false;
});
</script>
优秀。谢谢鲍里斯。 – CHS