I\'ve got a model class in KnockoutJS which has multiple values that I\'d like to subscribe to. Each subscription will perform the same task, like so:
funct
You can create some kind of an extension for this purpose. Simple example:
function subscribeMany(callback, observables) {
for (var i = 0; i < observables.length; i++) {
observables[i].subscribe(callback);
}
}
Usage:
var name = ko.observable();
var email = ko.observable();
var callback = function(value) {
console.log(value);
};
subscribeMany(callback, [name, email]);
name('test 1')
email('test 2')