Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 格式化json结果中的日期并显示在表angularjs中_Javascript_Json_Angularjs - Fatal编程技术网

Javascript 格式化json结果中的日期并显示在表angularjs中

Javascript 格式化json结果中的日期并显示在表angularjs中,javascript,json,angularjs,Javascript,Json,Angularjs,我对一个页面执行get请求,该页面返回日期格式为dd/MM/yyyy的json。 我解析它并将其显示在如下表中 <script> angular.module("myApp",[]) .controller("mainController", function($scope, $http) { $http.get('backList.php',{params: {dta: $scope.dataSelected}}) .success(function

我对一个页面执行get请求,该页面返回日期格式为dd/MM/yyyy的json。 我解析它并将其显示在如下表中

<script>
angular.module("myApp",[])
.controller("mainController", function($scope, $http) {
    $http.get('backList.php',{params: {dta: $scope.dataSelected}})
            .success(function(data) { if("null" == data) 
                                        $scope.list=""; 
                                    else {
                                        $scope.list=data;
                                    }
                                    } )
            .error(function() { alert("Error retrieve data!"); });
    }
});
</script>

<body ng-controller="mainController">
<div>
<table>
  <tbody>
    <tr ng-repeat="row in list">
      <td align="center">{{row.dta_example}}</td>
      <td align="center"><input class="calendar" type="text" ng-model="row.dta_example" ng-value="row.dta_example" /></td>
    </tr>
  </tbody>
</table>
</div>
</body>
但失败。

尝试:

$scope.list[i].dta_example = new Date(key.dta_example);
此外,“null”不等于null。除非您的代码以某种方式传回“null”字符串,否则该测试将无法工作

在过滤器中使用

<script>
  angular.module("myApp",[])
  .controller("mainController", function($scope, $http) {
     $http.get('backList.php',{params: {dta: $scope.dataSelected}})
        .success(function(data) { if("null" == data) 
                                    $scope.list=""; 
                                else {
                                    $scope.list=data;
                                }
                                })
        .error(function() { alert("Error retrieve data!"); });
      }
   });
  angular.module("myApp").filter('momentFilter', function () {
     return function (date) {
       if (date === null || !angular.isDefined(date))
         return null;
       if (moment(date).isValid()) {
         return moment(date).format('DD. MM. YYYY HH:mm');
       }
       return date;
    }
  });
</script>

<body ng-controller="mainController">
<div>
 <table>
   <tbody>
     <tr ng-repeat="row in list">
       <td align="center">{{row.dta_example | momentFilter }}</td>
       <td align="center"><input class="calendar" type="text" ng-model="row.dta_example" ng-value="row.dta_example" /></td>
     </tr>
   </tbody>
 </table>
</div>
</body>

只是一个关于日期的注释-我再也不会使用momentjs以外的任何东西了,它会让你的生活变得更加轻松-我在代码中添加了ng value=row.dta_示例| momentFilter并将格式修改为momentdate.format'DD/MM/yyyyy';但仍然是不正确的。如果我输入2012年12月12日这样的日期,我会收到此警告,指定的值12/12/1902不符合要求的格式yyyy-MM-dd。并且会填充行。例如,2012年12月12日星期三。。。。。。。我希望它和我2012年12月12日发布的一样
<script>
  angular.module("myApp",[])
  .controller("mainController", function($scope, $http) {
     $http.get('backList.php',{params: {dta: $scope.dataSelected}})
        .success(function(data) { if("null" == data) 
                                    $scope.list=""; 
                                else {
                                    $scope.list=data;
                                }
                                })
        .error(function() { alert("Error retrieve data!"); });
      }
   });
  angular.module("myApp").filter('momentFilter', function () {
     return function (date) {
       if (date === null || !angular.isDefined(date))
         return null;
       if (moment(date).isValid()) {
         return moment(date).format('DD. MM. YYYY HH:mm');
       }
       return date;
    }
  });
</script>

<body ng-controller="mainController">
<div>
 <table>
   <tbody>
     <tr ng-repeat="row in list">
       <td align="center">{{row.dta_example | momentFilter }}</td>
       <td align="center"><input class="calendar" type="text" ng-model="row.dta_example" ng-value="row.dta_example" /></td>
     </tr>
   </tbody>
 </table>
</div>
</body>