我想排序我的json數據由日期但它不工作。這是我正在嘗試的。請糾正我在哪裏,我會犯錯按日期排序JSON數據javascript
示例代碼
var temp = [{
"id": 17608,
"title": "abc",
"start": "2016-03-23 06:13:00.0",
"backgroundColor": "#000000",
"borderColor": "#000000",
"textColor": "#fff"
}, {
"id": 17608,
"title": "def",
"start": "2016-04-13 06:13:00.0",
"backgroundColor": "#000000",
"borderColor": "#000000",
"textColor": "#fff"
}, {
"id": 17608,
"title": "ghi",
"start": "2016-04-08 06:13:00.0",
"backgroundColor": "#000000",
"borderColor": "#000000",
"textColor": "#fff"
}];
console.log(temp);
temp.sort(function(a, b) {
if (new Date(a.start) == new Date(b.start)) {
return a.row == b.row ? 0 : +a.row > +b.row ? 1 : -1;
}
return new Date(a.start) > (b.start) ? 1 : -1;
});
console.log(temp);
這不是JSON!它是一個帶有對象的Javascript數組。 – deceze