I am trying to create a new account which contains an inner array but I get an error:
Uncaught Error: The argument passed when initializing an observable array must be an array, or null, or undefined.
Any ideas why this is not working?
<script>
function Account(id, name, balance, deposits) {
this.Id = id;
this.Name = name;
this.Balance = balance;
this.Deposits = deposits;
}
var myAccountViewModel = function ()
{
this.Accounts = ko.observableArray([
new Account(1, "A1", 100, [1,2]),
new Account(2, "A2", 200, [2]),
new Account(3, "A3", 300, [2, 3]),
new Account(4, "A4", 400, [2,3]),
])
}
ko.applyBindings(myAccountViewModel);
</script>
HTML
<table>
<thead>
<tr>
<th>S.No</th>
<th>ID</th>
<th>Name</th>
<th>Balance</th>
</tr>
</thead>
<tbody data-bind="foreach: {data:Accounts, as:'Account'}">
<tr>
<td data-bind="text:($index()+1)"></td>
<td data-bind="text:Account.Id"></td>
<td data-bind="text:Account.Name"></td>
<td data-bind="text:Account.Balance"></td>
<!--<td>
<ul data-bind="foreach: {data:Deposits, as:'Amount'}">
<li data-bind="text:(Account().Name + 'Deposited ' + Amount())"></li>
</ul>
</td>-->
</tr>
</tbody>
</table>