I have a viewModel:
var teamViewModel = {
teams: ko.observableArray([]),
selectedTeam: ko.observable(1),
clearTeams: function(){
this.teams.removeAll();
},
addTeam: function (id, name, isChecked) {
t = new team(id, name, isChecked);
this.teams.push(t);
}
};
I want the selectedTeam().id to be initialized as 1, but every time a function is called on page load which references teamViewModel.selectedTeam().id the value is returned as undefined.
How can I initialize this value to 1 before the the function is called?
You should initialize
selectedTeamwith a new instance ofteam: