Reputation: 2339
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?
Upvotes: 0
Views: 73
Reputation: 16465
You should initialize selectedTeam
with a new instance of team
:
selectedTeam: ko.observable(new team(1, "", false))
Upvotes: 1