订单在ng-repeat中

时间:2015-03-12 12:08:48

标签: javascript angularjs object ng-repeat

JS:

$scope.termexamlist = {
    0:{
        0id:"1",
        1name:"Doe, John",
        2term1:"89"
    },
    1:{
        0id:"2",
        1name:"Aayt, Ray",
        2term1:"90"
    }
}; 

HTML:

<tr ng-repeat="t in termexamlist">
    <td ng-repeat="(key,value) in t">{{value}}</td>                 
</tr>

我得到了这个ng-repeat代码,该代码生成了他们的学期考试成绩的学生列表,我希望按1name对其进行排序,但它不起作用我用<tr ng-repeat="t in termexamlist | orderBy:'1name' ">但它没有工作。我也尝试了不同的编码,但它也没有用。对不起,我只是angularjs编程的初学者。谢谢你的帮助:D

3 个答案:

答案 0 :(得分:2)

声明数组时不应该放置标识符

$scope.termexamlist = [
  {
    0id:"1",
    1name:"Doe, John",
    2term1:"89"
  },
  {
    0id:"2",
    1name:"Aayt, Ray",
    2term1:"90"
   }
]; 

这就足够了,让你可以迭代它并订购它。

此外,你的变量前缀的方式很奇怪,但这不属于我的业务

答案 1 :(得分:0)

$scope.termexamlist = [
      {
        0id:"1",
        1name:"Doe, John",
        2term1:"89"
      },
      {
        0id:"2",
        1name:"Aayt, Ray",
        2term1:"90"
      }
    ]; 

删除数据中的0和1,它将正常工作

答案 2 :(得分:0)

我现在得到它,我在对象的键上添加下划线,所以它看起来像$scope.termexamlist={0:{_0id:"1",_1name:"Doe, John",_2term1:"89"}}。我保留了数字coz chrome对json_encode

的返回数据进行排序
相关问题