Angular.js使用JSON文档中的单个元素

Angular.js使用JSON文档中的单个元素,json,angularjs,date,formatting,Json,Angularjs,Date,Formatting,我有一些JSON,例如 [{ 'name': 'test', 'phone': '012345678', 'date': '02/03/2014' }, { ... } ] 控制器类似于: var app = angular.module('App', []); app.controller('NameListCtrl', function($scope, $http) { $http.get('/api/v1/names.json')

我有一些JSON,例如

  [{
    'name': 'test',
    'phone': '012345678',
    'date': '02/03/2014'
   },
   { ... }
  ]
控制器类似于:

var app = angular.module('App', []);


app.controller('NameListCtrl', function($scope, $http) {

    $http.get('/api/v1/names.json').success(function(names) {
            $scope.names = names;
    });
});
div#names(ng-controller="NameListCtrl")
   li.course_list(ng-repeat="name in names | orderBy:'date1'")
    span
     {{name.date}})                    // I want to do some formatting on this
    span
     {{name.name}}
HTML/JADE类似于:

var app = angular.module('App', []);


app.controller('NameListCtrl', function($scope, $http) {

    $http.get('/api/v1/names.json').success(function(names) {
            $scope.names = names;
    });
});
div#names(ng-controller="NameListCtrl")
   li.course_list(ng-repeat="name in names | orderBy:'date1'")
    span
     {{name.date}})                    // I want to do some formatting on this
    span
     {{name.name}}

我想在每个日期执行格式化操作,有没有不使用过滤器的方法?我看到一些东西使用
$httpProvider

在控制器中实现它。。。插入您自己的
filter
func

app.controller('NameListCtrl', function($scope, $http, $filter) {

    $http.get('/api/v1/names.json').success(function(names) {
          angular.forEach(names, function(item){
              item.date = $filter('date')(item.date, "shortDate");
          });
          $scope.names = names;
    }); 
 });
您也可以使用jade并执行以下操作:

{{name.date|date:'shortDate'}})    

你想怎么处理这个日期?为什么不使用过滤器呢,这是它们为内置日期过滤器而构建的
({date\u expression | date:date:format}}})
?如果我这样做,我的格式现在似乎是正确的,但是
orderBy
不再工作……如果将日期更改为某个人工字符串,则会出现问题。因为您正在进行字符串排序。。。我建议使用sep字段
item.dateformatted=formatfunc(item.date)。
或*使用第二个示例,使用它时只需在模板中对其进行格式化。是的,我添加了
item.orig=item.date
并按
orig
排序