Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.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 字符串格式的智能表日期和金额排序_Javascript_Angularjs_Date Sorting_Smart Table - Fatal编程技术网

Javascript 字符串格式的智能表日期和金额排序

Javascript 字符串格式的智能表日期和金额排序,javascript,angularjs,date-sorting,smart-table,Javascript,Angularjs,Date Sorting,Smart Table,在智能表格中,排序很容易。但当日期和金额为字符串格式时,如何排序 app.controller('basicsCtrl', ['$scope', function (scope) {scope.rowCollection = [ {firstName: 'Laurent', lastName: 'Renard', birthDate:'1987-05-21', balance: '1,20,000', email: 'whatever@gmail.com'}, {firstName: 'Blan

在智能表格中,排序很容易。但当日期和金额为字符串格式时,如何排序

app.controller('basicsCtrl', ['$scope', function (scope) {scope.rowCollection = [
{firstName: 'Laurent', lastName: 'Renard', birthDate:'1987-05-21', balance: '1,20,000', email: 'whatever@gmail.com'},
{firstName: 'Blandine', lastName: 'Faivre', birthDate: '1987-04-25', balance: '2,000', email: 'oufblandou@gmail.com'},
{firstName: 'Francoise', lastName: 'Frere', birthDate: '1955-08-27', balance: '4,23,000', email: 'raymondef@gmail.com'}];
}]);
我无法使用json中的format函数。它的投掷错误

formatFunction: function (value, formatParameter) {
return value[0];// some function to change string to date.
}
遵循此文档


有人帮我吗?我是这个领域的新手…

您可以使用过滤器来格式化字符串中的日期

app.filter('formatter', function () {
    return function (inputArray) {
        angular.forEach(inputArray,function(item,index){
            item.birthDate = new Date(item.birthDate)
        });
        return inputArray;
    };
});
然后在html中使用它:

<smart-table rows="rowCollection | formatter"></smart-table>

对于解析日期,我建议