0
私のviewmodel:グラブ正しいデータ
function AddEmployeesViewModel() {
var self=this;
self.names=ko.observableArray();
}
AddEmployeesViewModel.prototype.addEmployee=function(){
???
};
$.getJSON('/xxx.json').then(function(data){
addEmployeesViewModel.names([]);
for (i=0; i<data.length; i++) {
addEmployeesViewModel.names.push({id:data[i].id,name:data[i].name});
}
},
function(){
console.log('failure');
}
);
var addEmployeesViewModel=new AddEmployeesViewModel();
ko.applyBindings(addEmployeesViewModel);
と私のモデル:
<div>
<!-- ko foreach: names -->
<div>
<input type="checkbox" data-bind="checked: $root.addEmployee"><span data-bind="text: name"></span>
</div>
<!-- /ko -->
</div>
私の問題は、名前にするたびに、対応するIDを返すためにaddEmployee機能を作ることですチェックボックスを選択します。それを達成するための最良の方法はどれですか?