鉴于以下内容,我想按displayOrder
angular.module('app').value('sidebarMenus', {
'Sites': {
displayName: 'Sites',
displayOrder: 0
},
'Inspections': {
displayName: 'Inspections',
displayOrder: 1,
items: [
{ name: 'Create New', state: 'Admin.UserList' }
]
},
'Permits': {
displayName: 'Permits',
displayOrder: 2
},
'Compliance': {
displayName: 'Compliance',
displayOrder: 3
},
'Accounts': {
displayName: 'Accounts',
displayOrder: 4
},
'Documents': {
displayName: 'Documents',
displayOrder: 5
},
'Queries': {
displayName: 'Queries',
displayOrder: 6
},
'Reports': {
displayName: 'Reports',
displayOrder: 7
},
'Admin': {
displayName: 'Admin',
displayOrder: 8,
items: [
{ name: 'Users', state: 'Admin.UserList' },
{ name: 'Groups', state: 'Admin.GroupList' },
{ name: 'Workgroups', state: 'na' },
]
}
});
我有这个,但它不起作用。出于某种原因,默认情况下按字母顺序排序。
<li data-ng-repeat="item in sidebar.menus | orderBy: item.displayOrder">
<a href="javascript:;" data-ng-bind="item.displayName" data-ng-click="sidebar.menu.setMenu(item)"></a>
</li>
结果
Accounts
Admin
Compliance
Documents
Inspections
Permits
Queries
Reports
Sites
答案 0 :(得分:5)
sidebarMenus
是一个对象。 orderBy
只能应用于数组。您无法对对象的属性进行排序;)