I am mapping two related models by storing the primary key of related model in the first and then computing the actual model at runtime. This cause my model to access the view-model list. Is there any better way of relating these models
function Address(data){
this.id = data.id;
}
function Person(data){
var self = this;
self.addressIdList = ko.observableArray();
this.addresses = ko.computed(function(){
return _.filter(_.map(self.addressIdList(), function(id){
return _.find(vm.addressList(), function(a){
return a.id == id;
});
}),function(item){ return typeof item != 'undefined';});
});
}
function ViewModel(){
this.personList = ko.observableArray();
this.addressList = ko.observableArray();
}
var vm = new ViewModel();
- I want to remove access to view-model (vm.addressList()) from Person.addresses(). How can I do this?
- Will JayData or some other library help me ?