function translateDataToTre2(data) {
let parents = data.filter(value => value.pid === 'undefined' || value.pid === null || value.pid === '')
let children = data.filter(value => value.pid !== 'undefined' && value.pid !== null && value.pid !== '')
let translator = (parents, children) => {
parents.forEach((parent) => {
children.forEach((current, index) => {
i++
if (current.pid === parent.id) {
let temp = JSON.parse(JSON.stringify(children))
temp.splice(index, 1)
translator([current], temp)
typeof parent.children !== 'undefined' ? parent.children.push(current) : parent.children = [current]
}
})
})
}
translator(parents, children)
return parents
}