gpt4 book ai didi

angularjs - Angular 误差: $parse:syntax Syntax Error

转载 作者:行者123 更新时间:2023-12-03 08:21:11 25 4
gpt4 key购买 nike

我正在构建一个示例应用程序(请参阅plunk https://plnkr.co/edit/vDXcSPrOjw5qvBQKcYvw?p=preview)。

<!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>

当我将属性名称从“80th_time”更改为“th_time”时, Angular 解析起作用。如果我将属性名称保持为“80th_time”,则会出现以下$ parse异常:

https://docs.angularjs.org/error/ $ parse/语法?p0 = th_time&p1 = is%20an%20unexpected%20token&p2 = 3&p3 = 80th_time%7CparseFloat&p4 = th_time%7CparseFloat

有什么想法为什么会这样?

为了对此进行测试(即触发异常),您可以运行插件,然后尝试单击标题“每80次”(以触发基于此列的排序)。

最佳答案

使用item.80th_time表示法时,只能使用有效的variable names。为了使用以数字开头的数字,您需要将其作为item['80th_time']进行访问。

关于angularjs - Angular 误差: $parse:syntax Syntax Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38112338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com