所以在我的应用程序中,我有一小段信息称为 suntis 。每个sunti都可以有.tags,.author,.ancestor,.short_id和其他一些属性。
说我有以下
的suntisunti_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"
}
然后我有一个以下的sunti,其中祖先字段指向上述sunti的short_id:
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
}
我想检查传入的suntis,看看他们是否有一个ancestor_id,它已存在于我的存储/缓存suntis-seen-so-far中。
现在我有类似
的东西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?)
}
})
我希望结果是:
{
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
}
}
}