【发布时间】:2016-07-09 16:45:33
【问题描述】:
总结:有一个多级的父子评论系统。即
示例:
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 的子级 等等..
要求:
我们想基于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/
我看到很多关于 * 的问题,但没有按要求工作。
任何直接的帮助都将是非常可观的。谢谢
【问题讨论】:
-
所以你想要一个平面列表?
-
如果结构应该保留,您只能在同一级别上排序。
-
@georg,不是一个平面列表。我希望根据
CommentCreateStamp属性以排序方式对数据进行排序。最新的 cmets 应该位于顶部,并且与子层次结构相同。我更新了 JSON 对象。请立即检查。 -
@NinaScholz,没有办法对分层结构进行排序?
-
试试这个链接希望它对你有帮助。 *.com/questions/13758467/…
标签: javascript jquery json sorting