У меня есть массив slides
, который содержит переменную stars
внутри него. Мне нужно получить значение для stars
на каждом слайде, а затем использовать это число, чтобы повторить строку HTML для каждого слайда.
Я могу получить значение stars
, но оно повторяет все 6 слайдов и предоставляет их значения 6 раз.
Мне нужно получить все значения stars
только 1 раз.
var slides = [
{
'text' : 'The staff was fantastic and very friendly. I would definitely recommend them to anyone. The care has been great!! - ONLINE REVIEWER',
'stars' : 4
},
{
'text' : 'The staff was fantastic and very friendly. I would definitely recommend them to anyone. The care has been great!! - ONLINE REVIEWER',
'stars' : 3
},
{
'text' : 'The staff was fantastic and very friendly. I would definitely recommend them to anyone. The care has been great!! - ONLINE REVIEWER',
'stars' : 2
},
{
'text' : 'The staff was fantastic and very friendly. I would definitely recommend them to anyone. The care has been great!! - ONLINE REVIEWER',
'stars' : 1
},
{
'text' : 'The staff was fantastic and very friendly. I would definitely recommend them to anyone. The care has been great!! - ONLINE REVIEWER',
'stars' : 5
},
{
'text' : 'The staff was fantastic and very friendly. I would definitely recommend them to anyone. The care has been great!! - ONLINE REVIEWER',
'stars' : 2
}
];
$scope.addStars = function(){
i = 1;
for (i=1; i<slides.length; i++) {
var starsCount = slides[i].stars;
var starsHTML = '<a href="#">☆</a>';
starsFinal = starsHTML.repeat(starsCount);
console.log(starsFinal);
}
}