これがうまくいかない理由を誰か説明できますか?
function MyViewModel() {
var data = [
{ forename: "Bob", age: 23 },
{ forename: "Alex", age: 19 },
{ forename: "Joe", age: 67 }
];
var persons = ko.observableArray(data);
useForEach = function () {
ko.utils.arrayForEach(persons, function (item) {
item.age(99);
});
};
return {
persons: persons,
useForEach: useForEach
}
}
var vm = new MyViewModel();
ko.applyBindings(vm);
ビューで年齢が更新されることを望んでいますが、何も起こりません....ここに私のビューがあります:
<button data-bind="click: useForEach ">useForEach</button>
<table>
<thead>
<tr>
<th>Forename</th>
<th>Age</th>
</tr>
</thead>
<tbody data-bind="foreach: persons">
<tr>
<td data-bind="text: forename"></td>
<td data-bind="text: age"></td>
</tr>
</tbody>
</table>