- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
function * getTreePost(postsInfo, id) {
var parent = _.filter(postsInfo, function (item) {
return Boolean(item._id == id);
});
var children = _.filter(postsInfo, function (item) {
return Boolean(item.parentId);
});
return _.union(parent, findChildren(id, children));
function findChildren(parentId) {
if (parentId) {
var data = _.where(children, {parentId: parentId});
var ret = [];
if (data.length) {
_.each(data, function (item, index) {
var data_r = findChildren(item._id);
if (data_r.length) {
ret = _.union(data_r, ret);
}
});
return _.union(data, ret);
} else
return [];
} else return [];
}
}