knockout.js - Dynamically adding data to observableArray -
i have viewmodel , function add together info 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 trying print out values in items array, x , y never displayed. though alert pops a, b, x, , y. doing wrong?
<div data-bind="foreach: {data: items, as: 'item' }"> <span data-bind="text: item"></span> </div>
thanks.
this.items()
exposes underlying array of ko.observablearray()
, normal array. need utilize this:
this.items.push('x'); this.items.push('y');
demo
knockout.js
No comments:
Post a Comment