Angular JS order select using key/value

前端 未结 1 801
遥遥无期
遥遥无期 2021-01-15 19:27

I just asked about generating a select from key/value map instead of array: AngularJS select box generated from object

That is all working fine now: http://jsfiddle.

1条回答
  •  -上瘾入骨i
    2021-01-15 20:06

    Solution 1: You can use another array to store the order of the fields. For this you would need to use ng-repeat in place of ng-options:

    $scope.studentAddressFields = [
        "select",
        "letter",
        "photograph"
    ]
    

    HTML:

    
    

    Solution 2: Using a filter:

    HTML:

    
    

    Filter:

    myApp.filter('getOrdered', function() {
        return function(input) {
            var ordered = {};
            for (var key in input){            
                ordered[input[key]["code"]] = input[key];
            }           
            return ordered;
        };
    });
    

    0 讨论(0)
提交回复
热议问题