V
V
Vladimir Tyutimov2016-07-01 11:28:48
JavaScript
Vladimir Tyutimov, 2016-07-01 11:28:48

How to create objects in a loop?

Hello. Tell me how to correctly form an array of objects in JS?
With the help of a geocoder, I received several points from Yandex.maps. They are stored in res.geoObjects . Now I need to display a list with these addresses on the map. To do this, I need to form an array with yamps.control.ListBoxItem objects , which I do in a loop, but the code is executed up to the line var itemBoxItem = new yamps.control.ListBoxItem , and then nothing, there are no errors in the console either. How can I properly form this array?

var countGeoObject = res.geoObjects.getLength();
    for (var i=0; i < countGeoObject; i++)  {
        var content = res.geoObjects.get(i).getAddressLine();
        var center = res.geoObjects.get(i).geometry.getCoordinates();
        var itemBoxItem = new yamps.control.ListBoxItem({
             data: {
                 content: content,
                 center: center,
                 zoom: 9
            }
        });
        console.log(itemBoxItem);
        listBoxItems.push(itemBoxItem);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
forgotten, 2016-07-01
@BidiBom

yamps → ymaps

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question