I have some trouble with knockout nested observableArrays.
My Data looks like this:
var myData = {
Id: 123,
Name: "string here",
Categories: [
{
Id: 12,
Name: "Category Name",
Products: [
{
Id: 1,
Name: 'Product1 name',
SomethingElse: '...'
},
{
Id: 2,
Name: 'Product2 name',
SomethingElse: '...'
}
]
},{
// another category ...
}
]
}
My ViewModel looks like this:
viewModel = function () {
var self = this;
this.Id = menueItem ? ko.observable(menueItem.Id) : ko.observable(0);
this.Name = menueItem ? ko.observable(menueItem.Name) : ko.observable();
this.Categories = menueItem ? ko.observableArray(menueItem.Categories) : ko.observableArray([]);
// ...
}
So my question is, how get the Products
of each Category
also to an observableArray
.
The properties in Products not have to be observable. In my Application I have to add and remove Categories and Products.