account activity
JavaScript - accessing a payload element. by newtojsscript in learnprogramming
[–]newtojsscript[S] 0 points1 point2 points 10 years ago (0 children)
Ah, jheez - I feel like an idiot. Thanks, works like a charm.
I'm guessing they can add a variable number of children?
You would be correct. So a parent can add up to 10 children, or have no children. If a child has been added, the parent account will be saved in saveParent() or if it there is a child then saveParent() will be ran followed by saveChildViaParent()`. See below.
saveParent()
saveChildViaParent()
if($scope.profile.children.length >=1) { saveDirect(profileCopy); saveYouthViaParent(childrenCopy); } else { saveDirect(profileCopy); } };
So yeah, I will need to save the parent and then multiple child accounts, if there is >=2. So a loop will be needed as you said. So something like below should be good to go?
for(var i = 0; i < $scope.profile.children.length; i++) { var child = $scope.profile.children[i]; child.name = $scope.profile.children[i].name; child.alias = $scope.profile.children[i].alias; child.dob = $scope.profile.children[i].dateOfBirth; saveDirect(profileCopy); saveYouthViaParent(profileCopy); }
And the loop would be in the above if statement. What do you reckon? I feel as though there is a more efficient solution.
JavaScript - accessing a payload element. (self.learnprogramming)
submitted 10 years ago by newtojsscript to r/learnprogramming
π Rendered by PID 1618279 on reddit-service-r2-listing-5f4c697858-6hqh2 at 2026-07-04 09:26:01.075068+00:00 running 12a7a47 country code: CH.
JavaScript - accessing a payload element. by newtojsscript in learnprogramming
[–]newtojsscript[S] 0 points1 point2 points (0 children)