如何为可观察数组创建的列表创建按字母顺序分隔的分隔符?我希望列表按姓氏划分。它已经排序,它只需要分隔线。
该列表在此处创建:
function GetUsersByLocation(){
var url = 'http://localhost/Service.svc/GetUsersByLocation/'+localStorage.CurrentLocationId;
var jqxhr =
$.getJSON(url,
function (data)
{
userViewModel.clearUsers();
$.each(data.GetUsersByLocationResult, function (key, val) {
userViewModel.addUser(val.FirstName, val.LastName);
});
ko.applyBindings(userViewModel, document.getElementById("usersListView"));
})
.success(function () { $('#usersListView').listview('refresh'); })
}
并在这里实现:
<div>
<ul id="usersListView" data-bind="template: {name: 'usersListTemplate', foreach: users}" data-role="listview" data-filter="false" data-filter-placeholder="enter a colleague's name..."></ul>
</div>
<script id="usersListTemplate" type="text/html">
<li><a href="javascript: void(0)">
<table>
<tr class="colleague">
<td>
<table>
<tr><td><span class="firstname_" data-bind="text: firstname"></span> <span data-bind="text: lastname"></span></td></tr>
</table></a>
</td>
</tr>
</table>
</li>
</script>