Reputation: 13835
So I have a view model like so:
var viewModel = function() {
var self = this;
this.chartSeries = ko.observableArray(['All Series']);
}
ko.applyBindings(new viewModel());
$(function (){
//I want to access it here
}
How do I accomplish this?
when I try viewModel().chartSeries
, viewModel.chartSeries
, viewModel.chartSeries()
etc. I get undefined errors.
Upvotes: 0
Views: 2752
Reputation: 7194
You are getting undefined errors because you don't have an instance of the view model in scope. The easiest thing would be to do:
var vm = new viewModel();
ko.applyBindings(vm);
$(function (){
// do stuff with vm
vm.chartSeries.push('Series A');
}
Upvotes: 5