I have this viewmodel and a function to add data to it,
function viewModel() {
this.loadData = function() {
this.Items().push('X');
this.Items().push('Y');
};
this.Items = ko.observableArray(['A', 'B']);
}
var vm = new viewModel();
ko.applyBindings(vm);
vm.loadData();
alert(vm.Items());
I am trying to print out the values in Items array, but X and Y are never displayed. Though the alert pops up A, B, X, and Y. What am I doing wrong?
<div data-bind="foreach: {data: Items, as: 'item' }">
<span data-bind="text: item"></span>
</div>
Thanks.