I have the following KnockoutJS code in order to make a databinding for a Addresses Form Editor where I can have 4 address types (“home”, “office”, etc).
Right now everything is working great but the selectedAddress is being hardcoded to be the index 0
self.selectedAddress = ko.observable(self.addresses[0]);
Instead of doing this I want to selected the first address object that has data filled in.
Any clue on how to do this?
Appreciate.
Knockout’s utility function provides the very convienent
arrayFirstfunction, which makes this simple:Here is the updated fiddle.
Here is a handy reference for KO’s utility functions: