2016-06-30 5 views
0

샘플 앱을 구축 중입니다 (plunk https://plnkr.co/edit/vDXcSPrOjw5qvBQKcYvw?p=preview 참조).

나는 "80th_time"에서 "th_time"각 구문 분석 작업에서 속성의 이름을 변경

<!DOCTYPE html> 
<html ng-app="myApp"> 

<head> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.min.js"></script> 
    <script src="https://cdn.rawgit.com/mattiash/angular-tablesort/master/js/angular-tablesort.js"></script> 
    <link rel="stylesheet" href="https://cdn.rawgit.com/mattiash/angular-tablesort/master/tablesort.css"> 
    <script> 
var myApp = angular.module('myApp', ['tableSort']) 
    .controller("tableTestCtrl", function tableTestCtrl($scope) { 
    $scope.items = [{ 
     "Id": "01", 
     "Name": "A", 
     "80th_time": "1.00", 
     "median_time": "1" 
    }, { 
     "Id": "02", 
     "Name": "B", 
     "80th_time": "10.00", 
     "median_time": "1" 
    }, { 
     "Id": "04", 
     "Name": "C", 
     "80th_time": "9.50", 
     "median_time": "10" 
    }, { 
     "Id": "03", 
     "Name": "a", 
     "80th_time": "9.00", 
     "median_time": "2" 
    }, { 
     "Id": "06", 
     "Name": "b", 
     "80th_time": "100.00", 
     "median_time": "2" 
    }, { 
     "Id": "05", 
     "Name": "c", 
     "80th_time": "1.20", 
     "median_time": "2" 
    }]; 
    }); 
    </script> 
</head> 

<body> 
    <div ng-controller="tableTestCtrl"> 
    <table border="1" ts-wrapper> 
     <thead> 
     <tr> 
      <th ts-criteria="Id">Id</th> 
      <th ts-criteria="Name|lowercase" ts-default>Name</th> 
      <th ts-criteria="80th_time|parseFloat">80th Per Time</th> 
      <th ts-criteria="median_time|parseFloat">Median Time</th> 
     </tr> 
     </thead> 
     <tbody> 
     <tr ng-repeat="item in items track by item.Id" ts-repeat> 
      <td>{{ item.Id }}</td> 
      <td>{{ item.Name }}</td> 
      <td>{{ item.80th_time }}</td> 
      <td>{{ item.median_time }}</td> 
     </tr> 
     </tbody> 
    </table> 
    </div> 
</body> 

. ?

https://docs.angularjs.org/error/ $ 구문 분석/구문 P0 = th_time & P1 =입니다 % 20an % 20unexpected % 20token & P2 = 3 & P3 = 나는 "80th_time"나는 다음과 같은 $ 구문 분석 예외가 같은 속성의 이름을 유지하는 경우 80th_time % 7CparseFloat & p4 = th_time % 7CparseFloat

왜 이런 일이 일어나는가?

이것을 테스트하려면 (즉 예외를 트리거하기 위해) plunk를 실행 한 다음 "80th Per Time"헤더를 클릭하십시오 (이 열을 기준으로 정렬을 트리거).

+0

문제가 80th_에서 변수 이름을 변경하여 고정되었다가 .. (기본적으로 자바 스크립트 변수 문제를) _80th_합니다. – mithrandir

답변

1

item.80th_time 표기법을 사용할 때 유효한 variable names을 사용하도록 제한됩니다. 번호로 시작하는 번호를 사용하려면 item['80th_time']으로 액세스해야합니다. MDN에서

+0

나를 이길 때까지 30 초 – pulse0ne

1

:

An object property name can be any valid JavaScript string, or anything that can be converted to a string, including the empty string. However, any property name that is not a valid JavaScript identifier (for example, a property name that has a space or a hyphen, or that starts with a number) can only be accessed using the square bracket notation.

관련 문제