angularJS ng重复字段和特殊字符

时间:2017-06-05 21:19:35

标签: javascript angularjs json

我希望使用angularjs将我的团队中的所有击球手及其统计数据从json文件显示到表格中。

HTML:

<table class="table" ng-controller="players">
      <tr ng-repeat="x in player | orderBy:orderByField:reverseSort">
        <td>{{x.player_name}}</td>
        <td>{{x.components.B_OBP}}</td>
        <td>{{x.components.B_K%}}</td>
      </tr>
 </table>

JS:

var baseballApp = angular.module('baseballApp', []);

baseballApp.controller('Players', function ($scope, $http) {
    $scope.message = 'Players';
    $http.get('http://example.com/myteam.json').then(function (response) {
        $scope.player = response.data;
    });
});

JSON:

{

    "player_name": "Mookie Betts",
    "positions": {
        "PR": 0,
        "LF": 0,
        "C": 0,
        "DH": 0,
        "SS": 0,
        "CF": 0,
        "P": 0,
        "RF": 53,
        "1B": 0,
        "2B": 0,
        "3B": 0,
        "PH": 0
    },
    "handedness": {
        "bats": "R",
        "throws": "R"
    },
    "player_type": "b",
    "components": {
        "B_OPS": ".882",
        "B_SLG": ".516",
        "B_BSR": "3.6",
        "B_TEAM": "",
        "B_PA": "643",
        "B_3B": "4",
        "B_RBI": "94",
        "B_AB": "581",
        "B_R": "95",
        "B_2B": "38",
        "B_BB": "51",
        "B_ISO": ".206",
        "B_UBR": "3.5",
        "B_WOBA": ".375",
        "B_GDP": "",
        "B_H": "180",
        "B_SEASON": "2017",
        "B_SO": "71",
        "B_SH": "3",
        "B_WGDP": "",
        "B_SPD": "5.5",
        "B_SF": "5",
        "B_IBB": "1",
        "B_SB": "21",
        "B_G": "145",
        "B_WSB": "0.1",
        "B_BB/K": "0.72",
        "B_AVG": ".310",
        "B_CS": "9",
        "B_OFF": "28.4",
        "B_WRC+": "132",
        "B_HR": "25",
        "B_K%": "0.111",
        "B_WAR": "5.6",
        "B_BB%": "0.08",
        "B_BABIP": ".317",
        "B_1B": "113",
        "B_HBP": "3",
        "B_WRAA": "30.2",
        "B_WRC": "106",
        "B_DEF": "4.1",
        "B_OBP": ".366"
    },
    "player_id": "13611"

},

我能够正确显示大多数统计数据,直到我获得具有特殊字符的统计数据,例如B_K%或B_WRC +

我一直收到此错误:

Unexpected end of expression: x.components.B_K%

我不完全确定如何逃避角色

{{x.components.["B_K%"]}}
似乎没有帮助

有没有人有想法?

1 个答案:

答案 0 :(得分:1)

尝试{{x.components["B_K%"]}}