So in my application I have small blocks of info called suntis. Each sunti can have .tags, .author, .ancestor, .short_id, and some other attributes.
Say I have a sunti with the following
sunti_one = {
content: "The nature of mankind is deep-down inseparable from the nature of the cosmos",
tags: "philosophy, cosmos, nature, man",
ancestor: "none",
short_id: "H18EIQ5p"
}
Then I have a sunti with the following, where the ancestor field points to the short_id of the above sunti:
sunti_two = {
content: "It's true that man and the cosmos are entertwined, but man is clearly embedded in the cosmos. Yet, does that mean necessarily that the cosmos is embedded in man, too?"
tags: "cosmos, entertwined, man, question"
ancestor: "H18EIQ5p", << right here
short_id: BkwV9q2a
}
I want to check incoming suntis to see if they have an ancestor_id that exists already in my stash/cache of suntis-seen-so-far.
Now I have something like
socket.on('load_sunti_from_cache', function(a_sunti_over_the_wire) {
angular.forEach($scope.suntis, function(single_sunti_in_stash) {
//check stash'd sunti short_ids against incoming ancestor_ids
//console.log(a_sunti_over_the_wire.ancestor + " \\\ over wire")
//console.log(single_sunti_in_stash.short_id + " /// sunti stash")
if (a_sunti_over_the_wire.ancestor == single_sunti_in_stash.short_id) {
console.log('Matching ancestor & short_id: ' + single_sunti_in_stash.short_id)
$scope.suntis. ...? (what do I put here so that the over_the_wire sunti gets appended as a descendent of the matching ancestor sunti?)
}
})
I want the result to be:
{
content: "The nature of mankind is deep-down inseparable from the nature of the cosmos",
tags: "philosophy, cosmos, nature, man",
ancestor: "none",
short_id: "H18EIQ5p",
descendents: {
{
content: "It's true that man and the cosmos are entertwined, but man is clearly embedded in the cosmos. Yet, does that mean necessarily that the cosmos is embedded in man, too?"
tags: "cosmos, entertwined, man, question"
ancestor: "H18EIQ5p"
short_id: BkwV9q2a
}
}
}
parentId
in the child elements – charlietfl 21 hours ago$scope.suntis[sunti_stash_index].descendents = []
and push into it as you said. – sova 13 hours ago