How i can change value of one column on the basis of another column value change.In the following code i want to update % column using marks columns value change.
HTML:
<table data-bind="foreach: users()">
<thead class="flip-content table-head">
<tr>
<th align="center">Name</th>
<th align="center">Marks</th>
<th align="center">% out of 100</th>
</tr>
</thead>
<tr >
<td data-bind="text: $data.name()"> </td>
<td>
<input data-bind="value: $data.marks()" />
</td>
<td data-bind='text: $data.percent()'></td>
</tr>
</table>
SCRIPT:
var UserModel = function () {
this.users = ko.observableArray([
{
id: 1,
name: ko.observable('Bob'),
marks: ko.observable(0),
percent: ko.computed(function () {
//percentage formula
}, this)
},
{
id: 2,
name: ko.observable('Jane'),
marks: ko.observable(0),
percent: ko.computed(function () {
//percentage formula
}, this)
}
]);
this.selectedUser = ko.observable(this.users()[0]);
}
var userModel = new UserModel();
ko.applyBindings(userModel);
How i can do this.