mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 06:25:50 +01:00
dont crash for undefined categories
This commit is contained in:
@@ -335,12 +335,14 @@ Categories.flattenCategories = function (allCategories, categoryData) {
|
||||
*/
|
||||
Categories.getTree = function (categories, parentCid) {
|
||||
parentCid = parentCid || 0;
|
||||
const cids = categories.map(category => category.cid);
|
||||
const cids = categories.map(category => category && category.cid);
|
||||
const cidToCategory = {};
|
||||
const parents = {};
|
||||
cids.forEach((cid, index) => {
|
||||
cidToCategory[cid] = categories[index];
|
||||
parents[cid] = _.clone(categories[index]);
|
||||
if (cid) {
|
||||
cidToCategory[cid] = categories[index];
|
||||
parents[cid] = _.clone(categories[index]);
|
||||
}
|
||||
});
|
||||
|
||||
const tree = [];
|
||||
|
||||
Reference in New Issue
Block a user