1
我有一个简单的应用程序,它显示了Angular中的数据行。当控制器初始加载数据时,我希望行以与添加到我的rows
阵列相同的顺序出现。所以,orderBy
属性最初将被设置为一个空字符串。点击列标题,然后将orderBy
属性设置为适当的值。AngularJS ngRepeat orderBy in Chrome
这是我的小提琴:http://jsfiddle.net/fLjMR/3/。
这里是我的JS:
function ctrl($scope)
{
var rows = [];
for(var i = 10;i < 30;i++)
{
rows.push({name: "Fake Name " + i, email: "fakeemail" + i + "@gmail.com"});
}
$scope.rows = rows;
$scope.orderBy = "";
};
这里是我的HTML:
<table ng-app ng-controller="ctrl">
<thead>
<th><a ng-click="orderBy='name'">Name</a></th>
<th><a ng-click="orderBy='email'">Email</a></th>
</thead>
<tbody>
<tr ng-repeat="row in rows | orderBy:[orderBy]">
<td>{{row.name}}</td>
<td>{{row.email}}</td>
</tr>
</tbody>
</table>
当我做到这一点在IE和FF,行intially出现在加入他们的顺序,但是当我做它在Chrome中,中间项目(在本例中为第20行)出现在列表的开头。为什么是这样?
呵呵。那么你知道些什么,解决了它。我知道你可以摆脱括号,但我打算稍后添加一些额外的参数。为什么括号会有所作为? – Dave
只是看了一眼角度来源。如果排序谓词(冒号后面的东西)是一个虚假值并返回未排序的数组,orderByFilter会短路。一个空字符串是一个虚假值。包含空字符串的数组不是虚假值,因此尝试使用该空字符串作为谓词进行排序。 –
好东西。我认为你钉了它!非常感谢! – Dave