Reputation: 11
I am new to knockout.In my viewmodel I have perform an action only when two observable arrays get populated from database. How can I achieve this?
Thanks in advance
Upvotes: 0
Views: 77
Reputation: 3907
The easiest way is to define computed
observable that checks length of every array and returns true
if both lengths are not zeroes.
self.bothPopulated = ko.computed(function(){
return self.array1().length > 0 && self.array2().length > 0;
});
Then just subscribe on it with appropriate action:
self.bothPopulated.subscribe(function(val){
if (val) alert('both populated');
});
Upvotes: 2