私は日付順にソートしようとしていますが、動作していないようです。なぜsortBy()が機能しないのですか
var data = JSON.parse(body);
_.sortBy(data,function(a){
return a.results;
});
しかし、出力はまだ間違っています。最後のいくつかの項目は適切な場所にありません。読み込まれるデータはこのようなものです。
{ "カウント":56、 "結果":[{ "日付": "2014-06-05T18:02:51"、 "ID": "LC8_L1T_TOA/LC80370352014156LGN01"}、{ "日付" : "2014-07-07T18:03:03"、 "id": "LC8_L1T_TOA/LC80370352014188LGN00"): "2014-06-21T18:02:55"、 "id": "LC8_L1T_TOA/LC80370352014172LGN00" }}、{"date": "2014-07-23T18:03:05"、 "id": "LC8_L1T_TOA/LC80370352014204LGN00"}、{"date": "2014-08-08T18:03:14"、 "id" : "LC8_L1T_TOA/LC80370352014236LGN00"}、{"date": "2014-08-24T18:03:17"、 "id": "LC8_L1T_TOA/LC80370352014236LGN00"}、{"date": "2014-09-09T18:03: {id}: "LC8_L1T_TOA/LC80370352014252LGN00"}、{"date": "2014-09-25T18:03:18"、 "id": "LC8_L1T_TOA/LC80370352014268LGN00"}、{"date": "2014- "id": "LC8_L1T_TOA/LC80370352014284LGN00"}、{"date": "2014-10-27T18:03:23"、 "id": "LC8_L1T_TOA/LC80370352014300LGN00"}、{10-11T18:03: 「date」:「2014-11-12T18:03:26」、「id ":" LC8_L1T_TOA/LC80370352014316LGN00 "}、{" date ":" 2014-11-28T18:03:24 "、" id ":" LC8_L1T_TOA/LC80370352014332LGN00 "}、{" date ":" 2014-12-14T18:03 :18 "、" id ":" LC8_L1T_TOA/LC80370352014348LGN00 "}、{" date ":" 2014-12-30T18:03:14 "、" id ":" LC8_L1T_TOA/LC80370352014364LGN00 "}、{" date ":" 2015 "id": "LC8_L1T_TOA/LC80370352015015LGN00"}、{"date": "2015-01-31T18:03:10"、 "id": "LC8_L1T_TOA/LC80370352015031LGN00"}、{-01-15T18:03: "date": "2015-02-16T18:03:01"、 "id": "LC8_L1T_TOA/LC80370352015047LGN00"}、{"date": "2015-03-04T18:02:56"、 "id": "LC8_L1T_TOA/LC80370352015063LGN00 "}、{" date ":" 2015-03-20T18:02:46 "、" id ":" LC8_L1T_TOA/LC80370352015079LGN00 "}、{" date ":" 2015-04-05T18:02:35 " "id": "LC8_L1T_TOA/LC80370352015095LGN00"}、{"date": "2015-04-21T18:02:34"、 "id": "LC8_L1T_TOA/LC80370352015111LGN00"}、{"date": "2015-05-07T18 LC28_L1T_TOA/LC80370352015127LGN00 "}、{" date ":" 2015-05-23T18:02:16 "、" id ":" LC8_L1T_TOA/LC80370352015143LGN00 "}、{" 02:18 "、" id " "2015-06-08T18:02:26"、 "id": "LC8_L1T_ TOD/LC80370352015159LGN00 "}、{" date ":" 2015-06-24T18:02:32 "、" id ":" LC8_L1T_TOA/LC80370352015175LGN00 "}、{" date ":" 2015-07-10T18:02:43 " 、 "id": "LC8_L1T_TOA/LC80370352015191LGN00"}、{"date": "2015-07-26T18:02:49"、 "id": "LC8_L1T_TOA/LC80370352015207LGN00"}、{"date": "2015-08- LC8_L1T_TOA/LC80370352015223LGN00 "}、{" date ":" 2015-08-27T18:03:00 "、" id ":" LC8_L1T_TOA/LC80370352015239LGN00 "}、{11T18:02:53"、 "id" : "id": "LC8_L1T_TOA/LC80370352015255LGN00"}、{"date": "2015-09-28T18:03:13"、 "id": "LC8_L1T_TOA/LC80370352015271LGN00": "2015-09-12T18:03:07" } "、"日付 ":" 2015-10-14T18:03:19 "、" ID ":" LC8_L1T_TOA/LC80370352015287LGN00 "}、 : "LC8_L1T_TOA/LC80370352015303LGN00"}、{"date": "2015-11-15T18:03:19"、 "id": "LC8_L1T_TOA/LC80370352015319LGN00"}、{"date": "2015-12-01T18:03: {id}: "LC8_L1T_TOA/LC80370352015335LGN00"}、{"date": "2015-12-17T18:03:21"、 "id": "LC8_L1T_TOA/LC80370352015351LGN00"}、{"date": "2016- 01-02T18:03:18 "、" id ":" LC8_L1T_TOA/LC803703 "date": "2016-01-18T18:03:18"、 "id": "LC8_L1T_TOA/LC80370352016018LGN00"}、{"date": "2016-02-03T18:03:15"、 " {id}: "LC8_L1T_TOA/LC80370352016050LGN00"}、{"date": "2016-02-19T18:03:06"、 "id": "LC8_L1T_TOA/LC80370352016050LGN00"}、{"date": "2016-03-06T18: {id}: "LC8_L1T_TOA/LC80370352016082LGN00"}、{"date": "2016-03-22T18:02:58"、 "id": "LC8_L1T_TOA/LC80370352016082LGN00" "id": "LC8_L1T_TOA/LC80370352016098LGN00"}、{"date": "2016-04-23T18:02:43"、 "id": "LC8_L1T_TOA/LC80370352016114LGN00"}、 {"date": "2016-05-09T18:02:46"、 "id": "LC8_L1T_TOA/LC80370352016130LGN00"}、{"date": "2016-05-25T18:02:50"、 "id": " {"date": "2016-06-10T18:02:54"、 "id": "LC8_L1T_TOA/LC80370352016162LGN00"}、{"date": "2016-06-26T18:03:01" 、 "id": "LC8_L1T_TOA/LC80370352016178LGN00"}、{"date": "2016-07-12T18:03:09"、 "id": "LC8_L1T_TOA/LC80370352016194LGN00"}、{"date": "2016-07- 28T18:03:13 "、" id ":" LC8_L1T_TOA/LC80370352016210LGN0 {0}}、{"date": "2016-08-13T18:03:15"、 "id": "LC8_L1T_TOA/LC80370352016226LGN00"}、{"date": "2016-08-29T18:03:23" {date}: "2016-09-14T18:03:26"、 "id": "LC8_L1T_TOA/LC80370352016258LGN00"}、{"date": "2016-09-30T18: {id:LC8_L1T_TOA/LC80370352016274LGN00}}、{"日付": "2016-04-30T18:08:59"、 "id": "LC8_L1T_TOA/LC80380352016121LGN00" 2016-05-16T18:08:57" 、 "ID": "LC8_L1T_TOA/LC80380352016137LGN00"}]}
まだ動作していないようです。 – John
何がうまくいかないのですか? '_.sortBy'はソートされた配列を返します。 'Array#sort'と同じように、in situでソートされません。 –
私はこれを行いましたvar sortedArray = []; sortedArray = _.sortBy(data.results、[function(a){ return a.date; }}); – John