-1

While filling the form i am sending the id of closedBy selected item like this

if (selectedClosedPlaces != undefined) {
            place.closedBy = selectedClosedPlaces.map(function(g) {
                return g._id;
            });
        } else {
            place.closedBy = ['no_name'];
        }

i am displaying it in html using {{place.closedBy}}.
i will be having json data like this

[{"_id":"56bc720bd0113ab80dd3cb2d","name":{"en":"fshu","de":"hfasj"},"closedBy":["no_name"],"category":{"_id":"56bb2999f197db040dc3b12b","name":{"en":"asdfdsf","de":"asdf"}}}},
{"_id":"56bc7238d0113ab80dd3cb2e","name":{"en":"jsfadk","de":"jkgdj"},"closedBy":["56bc720bd0113ab80dd3cb2d"],"category":{"_id":"56bb2999f197db040dc3b12b","name":{"en":"asdfdsf","de":"asdf"}}}}]

For the first one it will be null, so i gave some name like ['no_name']. after adding the first one only i can select closedBy using selectbox.
now i am returning id for the second one. i am having id for the second one in closedBy using, please check the json above. with that id i need to fetch that particular name
Example: i am having 56bc720bd0113ab80dd3cb2d id with this id i need to show that name.en and name.de =>fshu and hfasj . i am using service to get the values
//service code here

.service('PlaceService', function($http) {
    return {
        init: function(callback) {
            $http.get('/api/places').then(function(place_response) {
                callback(place_response);
            });
        }
    }
})

and in controller

PlaceService.init(function(place_response) {
            $scope.places = place_response.data;
        console.log($scope.places); //giving all the places details like the //above json.
       console.log($scope.places.closedBy); // Not giving closedBy value here

can anyone please help me

2
  • Have read this 3 times and can't figure out what you are asking Commented Feb 11, 2016 at 12:56
  • i am getting if (selectedClosedPlaces != undefined) { place.closedBy = selectedClosedPlaces.map(function(g) { return g._id; }); } else { place.closedBy = ['no_name']; } i am getting _id with this javascript code, i need to show the name.en and name.de with that particular id which i am getting Commented Feb 12, 2016 at 3:48

1 Answer 1

1

to find another first item with specific id inside array of objects you can use _underscore js lib, like this:

var yourWantedId = ...;    
var result = _.findWhere(selectedClosedPlaces, {"_id": yourWantedId });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.