要約:マルチレベルの親子コメントシステムがあります。Javascript - ネストされた値によるJSONオブジェクトのソート
例:
comment 1
comment 1-1
comment 1-1-1
comment 1-2
comment 1-2-1
comment 1-2-2
ここ
、comment 1
が親であるとcomment 1-1
& comment 1-2
の両方であるようにcomment 1
との子...
R等価:
property value
.i.eに基づいてオブジェクト全体のsorting
を達成したいと考えています。 timestamp
(最新のコメントまたは返信が上に表示されます)。
JSONオブジェクト:私はこれまで試した
{
"CommentText": "",
"CommentCreateStamp": "2016-03-22",
"Comments": [{
"CommentText": "comment 1",
"CommentCreateStamp": "2016-03-09",
"Comments": [{
"CommentText": "comment 1-1",
"CommentCreateStamp": "2016-03-15",
"Comments": [{
"CommentText": "comment 1-1-1",
"CommentCreateStamp": "2016-03-21",
"Comments": null
}]
}]
}],
"Comments": [{
"CommentText": "comment 2",
"CommentCreateStamp": "2016-03-12",
"Comments": [{
"CommentText": "comment 2-1",
"CommentCreateStamp": "2016-03-10",
"Comments": [{
"CommentText": "comment 2-1-1",
"CommentCreateStamp": "2016-03-14",
"Comments": null
}]
}]
}]
}
:
JSfiddleは:https://jsfiddle.net/asceeevb/
私はstackoverflowの上の質問をたくさん見たが要件ごとに機能していません。
すぐれたヘルプは、いずれも非常に高い評価を受けます。おかげ
ので、あなたがフラットなリストをしたいですか? – georg
構造が残っている必要がある場合は、同じレベルでのみソートできます。 –
@georgであり、フラットリストではありません。私は 'CommentCreateStamp'プロパティに基づいてソートされた方法でデータを必要とします。最新のコメントは上部にも子階層と同じに来るべきです。私はJSONオブジェクトを更新しました。今すぐご確認ください。 –