简体   繁体   中英

orderBy not working in angularjs with object name with a dash

I'm trying to sort by ascending order some dates I have in the object start-date. It seems to not work if there are dashes, according to some sources.

data-ng:repeat="medicationItem in medication | orderBy:['start-date','name']">

I am first trying to sort by date and then by alphabet. Is there something I am doing incorrectly?

Thank you in advanced.

Simplest way, just surround a field name with UTF8 code for quotation mark:

HTML

<li ng-repeat="item in items | orderBy:'\u0022Dashed-Key\u0022'">

JS

$scope.orderKey = '\u0022Dashed-Key\u0022';

I have had similar issues with attributes of objects that have hyphens in the name. So user['first-name'] which works for most things in Angular will not work with filters. In order for you to get the orderBy for start date to work. It will need to look like orderBy:['startDate', 'name'] and medicationItem will have to have an attribute medicationItem.startDate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM