--Hello,Trying to build a simple calculator in knockout to learn some more. The points value is being updated but the computer bonus value is only calculated once and never updates.What am I doing wrong here? https://codepen.io/vandenberg-the-designer/pen/NzMGGL
<table class="table"><thead><tr><th>Stat</th><th>Points</th><th>Points</th><th>Bonus</th></tr></thead><tbody data-bind="foreach: stats"><tr><td><span data-bind="text: name" /></span></td><td><input type="number" data-bind="value: points, valueUpdate: ['afterkeydown', 'input']"/></td><td><span data-bind="text: points"></span></td><td data-bind="text: bonus"></td></tr></tbody></table>
function Stat(name, initial) {var self = this;self.name = name;self.stat = ko.observable(initial);self.points = ko.observable(self.stat().points);self.bonus = ko.computed(function() {var bonus = self.stat().points / 2 - 5;return bonus;});}function statViewModel() {var self = this;self.stats = ko.observableArray([new Stat("STR", { statName: "STR", points: 10 }),new Stat("DEX", { statName: "DEX", points: 12 }),new Stat("CON", { statName: "CON", points: 14 }),new Stat("INT", { statName: "INT", points: 16 }),new Stat("WIS", { statName: "WIS", points: 18 }),new Stat("CHA", { statName: "CHA", points: 8 })]);}ko.applyBindings(new statViewModel());
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.