How to create an observable that is initialized by an object?
function Company(object) {
this.Code = object != undefined && object.Code != undefined ? ko.observable(object.Code) : ko.observable();
this.Name = object != undefined && object.Name != undefined ? ko.observable(object.Name).extend({ required: { message: "Nom de la companie est obligatoire" } }) : ko.observable().extend({ required: { message: "Nom de la companie est obligatoire" } });
};
//View Model
var company = new AddedCompany();
self.company = ko.observable(company);
I am not getting any exceptions in the console, but the binding does not work properly.
Is initializing an observable with an object possible in the first place?
Yes it is, but you need to use the with binding to change the context to the sub viewmodel (Company in this case)
The with binding can be used with and without virtual element