简体   繁体   中英

AngularJS: toArray orderBy not working with ng-repeat on key, value pair

The divs are being repeated properly with no errors but they are not in order based on value. I would eventually like to have functionality for the divs to be ordered by max and minimum value via buttons or a checkbox but I am stuck here. Any help would be greatly appreciated, thanks!

Here is my ng-repeat:

<div ng-repeat="(key, value) in frequency track by $index | toArray | orderBy:'value' ">
</div>

Here is my data:

$scope.frequency = [1: 138, 2: 147, 3: 144, 4: 144, 5: 148, 6: 140, 7: 145, 8: 176, 9: 142, 10: 136, 11: 164, 12: 146, 13: 146, 14: 133, 15: 163, 16: 158, 17: 157, 18: 133, 19: 156, 20: 149, 21: 148, 22: 149, 23: 149, 24: 144, 25: 161, 26: 142, 27: 166, 28: 144, 29: 137, 30: 154, 31: 172, 32: 138, 33: 128, 34: 143, 35: 160, 36: 152, 37: 136, 38: 140, 39: 145, 40: 150, 41: 143, 42: 147, 43: 157, 44: 160, 45: 150, 46: 135, 47: 137, 48: 136, 49: 135, 50: 173, 51: 137, 52: 162, 53: 182, 54: 154, 55: 171, 56: 123, 57: 161, 58: 127, 59: 129];

I am using the toArray filter found at the following address: https://github.com/petebacondarwin/angular-toArrayFilter/blob/master/toArrayFilter.js

对于toArray过滤器所需的object ,您需要像下面那样纠正您的对象。

$scope.frequency = {1: 138, 2: 147, ....};

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