读取json编号并以文本显示

时间:2014-10-09 10:09:10

标签: json angularjs

在我的表格中,我显示名称和分数,但分数出现在10,20,30,40等数字中。 我想要它,如果有人有10分,它应该是td表中的青铜成员{x.ponts},20表示银,30表示黄金,40表示精英。

你不需要解决它,只需要一些帮助,我做错了。

         <table>
                <tr ng-repeat="x in Id">
                    <td>{{ x.id }}</td>
                    <td>{{ x.name }}</td>
                    <td>{{ x.points }}</td>
                </tr>
            </table>


    <script>
        function customersController($scope, $http) {
        $http.get("mylocalhostlink")
        .success(function (response) { $scope.Number = response });
我认为这样的事情......我是否接近?

                angular.forEach($scope.Id, function (value) {

                    switch (value.status) {
                        case 10:
                            $scope.points = bronze;
                            break;
                        case 20:
                            $scope.points = silver;
                            break;
                        case 30:
                            $scope.points = gold;
                            break;
                        case 40:
                        $scope.points= elite;
                        break;

                        default:
                            console.log(value.status);


                    }



     </script>

1 个答案:

答案 0 :(得分:0)

试试这个,你需要创建一个points过滤器。 Plunker

<td>{{ x.points  | points }}</td>

添加点过滤器。

app.filter('points', function() {
    return function(input) {
        var point;
        switch (input) {
            case 10:
                point = 'bronze';
                break;
            case 20:
                point = 'silver';
                break;
            case 30:
                point = 'gold';
                break;
            case 40:
                point = 'elite';
                break;

            default:
                point = 'none';

        }

        return point;
    };
});