last day (15 days later) » 

10:17 PM
0
A: AngularJS/JavaScript creating a new object from another object

lucumaI am going to propose a solution that doesn't require grouping or doing anything with the original array data: Assuming we have this per the question: $scope.content = [{ banner_heading: "Services", id: 1}, {banner_text:'some text', id:2}, {banner_img:'service.jpg', id:3}]; We can write a fu...

 
Hmm I'm not sure why this is returning undefined for me.
 
Make sure the string you pass into getData is the extact name of the key.
 
Yes, I am...hmm confused..I want this to work, it's a great and simple solution
 
I posted a working plunker
 
Awesome, got it working. But my only problem remaining is that I don't have a way to get the individual ids
I need to be able to get the id to be able to handle a PUT request to edit each piece of the data (banner_heading, banner_text, banner_img)
 
10:17 PM
I added another function just to show you how, the _.find could be cleaned up into one for both but you now have the parts!
 
I don't understand how I can use that function to get the specific id of say banner_heading?
 
No problem, did you see the getId function I added?
 
Yes
I really appreciate all your help by the way
 
this code snippet, ` var row = _.find($scope.content, function(item) {
return n in item;
});`
is basically getting the row in your array so you can use row.id
that's all getId is doing
 
Oh ok, so I could do something like {{ getId('banner_heading') }}?
 
10:21 PM
yes
 
I see, okay I think that solves all my problems. I will happily accept your answer, thanks a ton Lucuma
 
Sure, glad to have helped
 
10:32 PM
Someone may write an answer that preprocesses the data (I did) but I find the function approach much simpler.
 

last day (15 days later) »