I want to bind and change multiple inputs to the same variable (so that they will always change together to the same value), but I can not figure this out. My code:
$(function () {
var AppVm = function () {
this.people = ko.observableArray([
{ firstName: 'Bert', lastName: 'Bertington' },
{ firstName: 'Charles', lastName: 'Charlesforth' },
{ firstName: 'Denise', lastName: 'Dentiste' }
]);
};
vm = new AppVm();
ko.applyBindings(vm);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<thead>
<tr><th>First name</th><th>Last name</th></tr>
</thead>
<tbody data-bind="foreach: people">
<tr>
<td>
<input type="text" data-bind="textInput: firstName"/>
</td>
<td>
<input type="text" data-bind="textInput: firstName"/>
</td>
</tr>
</tbody>
</table>
It loads the same value initially in both the text inputs, but when I change one of them , the other one does not update. How can I update them both at the same time?