javascript - angularjs orderBy not working right -


i have array form  $vars[1][1]["name"]     = "john"; $vars[1][1]["lastname"] = "doe"; $vars[1][2]["name"]     = "ely"; $vars[1][2]["lastname"] = "tim";   $vars[2][1]["name"]     = "brad"; $vars[2][1]["lastname"] = "vinnie"; $vars[2][2]["name"]     = "angelina"; $vars[2][2]["lastname"] = "van";  .....  $vars[10][1]["name"]     = "ela"; $vars[10][1]["lastname"] = "pearl"; $vars[10][2]["name"]     = "gustavo"; $vars[10][2]["lastname"] = "tim";  in php. after send angularjs , have  $scope.vararr = data.vars 

after in view have

<div ng-repeat="(key, det) in vararr| orderby: key">      {{det.name}} {{det.lastname}}  </div> 

the problem it's not taking array in order 1,2,3...10

it's taking $vars[1] after $vars[10] , after $vars[2]. instead of making order after number it's making after string.

this situation if have $vars[1][1] , $vars[1][2]...etc

if have $vars[1][1], $vars[2][1], .... $vars[10][1] take order after number.

in angular doc, says when use (key, value) method:

you need aware javascript specification not define order of keys returned object. (to mitigate in angular 1.3 ngrepeat directive used sort keys alphabetically.)

version 1.4 removed alphabetic sorting. rely on order returned browser when running key in myobj. seems browsers follow strategy of providing keys in order in defined, although there exceptions when keys deleted , reinstated. see https://developer.mozilla.org/en-us/docs/web/javascript/reference/operators/delete#cross-browser_issues

if not desired, recommended workaround convert object array sorted order prefer before providing ngrepeat. filter such toarrayfilter or implement $watch on object yourself.

one way handle flatten array single dimension before passing document. this question has several answers on how "flatten" multidimensional array in php.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -