javascript - AngularJS: HTML select to use values from map with ascending order on key -
i have map(bidirectional) of states. composed of statename , statecode. populated following html code cannot filter statecode or statename in ascending order.
<div class="col-sm-2"> <select ng-model="location.statecode" ng-change="loaddistricts();" ng-options="statename (statecode, statename) in stateoptions | orderby:'statecode'" class="form-control" id="state"></select> </div> //json object stateoptions = {'mh':'maharashtra','gj':'gujarat','mp':'madhya pradesh'};
you inverted statecode
, statename
:
ng-options="statename (statecode, statename) in stateoptions"
also, stateoptions
object, keys probably inserted alphabetically, depending on js virtual machine. orderby
filter here pointless, because (from documentation):
orders specified array expression predicate. ordered alphabetically strings , numerically numbers
see fiddle
edit: if want surely control order, rework structure array:
$scope.stateoptions = [{ statecode: 'mh', statename:'maharashtra' },{ statecode: 'gj', statename:'gujarat' },{ statecode: 'mp', statename:'madhya pradesh' }]; ng-options="state.statename state in stateoptions | orderby: 'statecode'"
see updated fiddle
Comments
Post a Comment