angularjs 排序依据 space
angularjs order by to object with space
我有一个用户列表,其中包含带有 space 的对象;
'User Name, First Name, Last Name, Phone #, User Image'
同时将此列表绑定到数据table,我这样做是为了实现我的数据
<tr ng-repeat="user in lstUsers | orderBy : ['User Name']>
<td> <img ngf-thumbnail="user['User Image']" alt="" id="imgUserImage{{$index}}" /></td>
<td>{{ user['User Name'] }}</td>
<td>{{ user['First Name'] }}</td>
<td>{{ user['Last Name'] }}</td>
<td>{{ user['Phone #'] }}</td>
</tr>
除了order by
,它工作得很好,如果我以这种方式使用它会出错orderBy : ['User Name']
Error: [$parse:syntax] Syntax Error: Token 'Name' is an unexpected token at column 6 of the expression [User Name] starting at [Name].
如果我使用 orderBy : '[User Name]'
,它会抛出这个错误;
Error: [$parse:syntax] Syntax Error: Token 'Name' is unexpected, expecting []] at column 7 of the expression [[User Name]] starting at [Name]].
如果我使用 orderBy : 'User Name'
,它会抛出这个错误;
Error: [$parse:syntax] Syntax Error: Token 'Name' is an unexpected token at column 6 of the expression [User Name] starting at [Name].
如果我在没有 space 的情况下使用它,就像这样 orderBy : 'UserName'
,它不会给出任何错误,但不会对 table 应用任何命令。
如何在table申请订单?任何形式的帮助将不胜感激。
您可以只用 UTF8 code
将字段名称括起来作为引号:
HTML
<tr ng-repeat="user in lstUsers | orderBy:'\u0022User Name\u0022'">
演示
angular.module("myApp",[]).controller("myController",function($scope){
$scope.lstUsers = [
{"User Name": 'SACHIN', age: 12},
{"User Name": 'AJMAL', age: 14},
{"User Name": 'SMITH', age: 15},
{"User Name": 'RICHARD', age: 16},
{"User Name": 'OSCAR', age: 32}
];
});
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="myController">
<div ng-repeat="user in lstUsers | orderBy:'\u0022User Name\u0022' ">
<h1>{{user['User Name']}}</h1>
<h1>{{user.age}}</h1>
</div>
</body>
</html>
我有一个用户列表,其中包含带有 space 的对象;
'User Name, First Name, Last Name, Phone #, User Image'
同时将此列表绑定到数据table,我这样做是为了实现我的数据
<tr ng-repeat="user in lstUsers | orderBy : ['User Name']>
<td> <img ngf-thumbnail="user['User Image']" alt="" id="imgUserImage{{$index}}" /></td>
<td>{{ user['User Name'] }}</td>
<td>{{ user['First Name'] }}</td>
<td>{{ user['Last Name'] }}</td>
<td>{{ user['Phone #'] }}</td>
</tr>
除了order by
,它工作得很好,如果我以这种方式使用它会出错orderBy : ['User Name']
Error: [$parse:syntax] Syntax Error: Token 'Name' is an unexpected token at column 6 of the expression [User Name] starting at [Name].
如果我使用 orderBy : '[User Name]'
,它会抛出这个错误;
Error: [$parse:syntax] Syntax Error: Token 'Name' is unexpected, expecting []] at column 7 of the expression [[User Name]] starting at [Name]].
如果我使用 orderBy : 'User Name'
,它会抛出这个错误;
Error: [$parse:syntax] Syntax Error: Token 'Name' is an unexpected token at column 6 of the expression [User Name] starting at [Name].
如果我在没有 space 的情况下使用它,就像这样 orderBy : 'UserName'
,它不会给出任何错误,但不会对 table 应用任何命令。
如何在table申请订单?任何形式的帮助将不胜感激。
您可以只用 UTF8 code
将字段名称括起来作为引号:
HTML
<tr ng-repeat="user in lstUsers | orderBy:'\u0022User Name\u0022'">
演示
angular.module("myApp",[]).controller("myController",function($scope){
$scope.lstUsers = [
{"User Name": 'SACHIN', age: 12},
{"User Name": 'AJMAL', age: 14},
{"User Name": 'SMITH', age: 15},
{"User Name": 'RICHARD', age: 16},
{"User Name": 'OSCAR', age: 32}
];
});
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="myController">
<div ng-repeat="user in lstUsers | orderBy:'\u0022User Name\u0022' ">
<h1>{{user['User Name']}}</h1>
<h1>{{user.age}}</h1>
</div>
</body>
</html>