这是您的工作示例:http: //jsfiddle.net/tkirda/TsgyJ/1/
html:
<thead>
<th data-bind="click: sort.bind($data, 'id') ">ID</th>
<th data-bind="click: sort.bind($data, 'name') ">Name</th>
<th data-bind="click: sort.bind($data, 'email') ">Email</th>
<th data-bind="click: sort.bind($data, 'city') ">City</th>
<th data-bind="click: sort.bind($data, 'created') ">Created</th>
</thead>
JavaScript:
self.sort = function (key) {
sortDir = sortDir * -1;
self.list.sort(function (a, b) {
return sortDir * (a[key] == b[key] ? 0 : (a[key] < b[key] ? -1 : 1));
});
self.moveToPage(1);
};