<script type="text/x-jquery-tmpl" id="conditionTemplate">
<tr>
<td style="padding-left: 5px;">
<span data-bind="visible: $index()==0">IF</span>
<select data-bind="attr: {id: 'ddlJoinOperator_'+ $index() } ,visible: $index()>0" style="width:50px;height:25px;">
<option value="and">AND</option>
<option value="or">OR</option>
</select>
</td>
<td style="padding-left: 25px;">
<table>
<tr>
<td>
<select data-bind="attr: {id: 'ddlleftparam_'+ $index() }" style="width:50px;height:25px;">
<option value="(">(</option>
<option value=" "></option>
</select>
</td>
<td style="padding-left: 30px;">
.Answer
<select data-bind="attr: {id: 'ddloperator_'+ $index() }" style="width:50px;height:25px;">
<option value="==">==</option>
<option value="!=">!=</option>
<option value="In">In</option>
<option value="Not In">Not In</option>
</select>
</td>
<td style="padding-left: 5px;">
<select data-bind="attr: {id: 'ddlOptions_'+ $index() }" style="width:240px;height:25px;">
</select>
</td>
<td style="padding-left: 5px;">
<select data-bind="attr: {id: 'ddlRightParam_'+ $index() }" style="width:50px;height:25px;">
<option value=")">)</option>
<option value=" "></option>
</select>
</td>
<td style="padding-left: 5px;">
<input type="button" data-bind="attr: {id: 'btnAdd_'+ $index() }">
</td>
</tr>
</table>
</td>
<td>
<input type="button" data-bind="attr: {id: 'btndelete_'+ $index() },visible: $index()>0">
</td>
</tr>
</script>
Above template is binding to the table as below.
<table id="tblConditions" data-bind="template: {name:'conditionTemplate', foreach: 'CondiotionXml'}">
</table>
$(function () {
$.ajax({
url: "/api/BranchSurvey/GetBranchLogicConditions",
success: function (lst) {
alert(lst.length);
BranchSurveyViewModel = ko.mapping.fromJS(lst);
ko.applyBindings(BranchSurveyViewModel, document.getElementById('tblConditions'));
return false;
}
});
});
My problem is in alert(lst.length); is giving value as 1. but in browser i am getting 12 rows repeating the template. As the length of list iam binding is 1 then why 12 times the template loop running.