javascript - For loop in twig with js
Get the solution ↓↓↓Solution:
You could work with a queue to solve this,
var prodId = new Array();
{% for pd in entities %}
prodId.push('{{ pd.id }}'); //Fill up the total queue
{% endfor %}
$(function() {
$(window).scroll(function() {
var scrollH = $(window).scrollTop() + $(window).height();
var documentH = $(document).height();
var infty_scrl_end = $('#sectiontop').offset().top;
if (scrollH > infty_scrl_end){
loadQueue();
}
});
loadQueue();
});
function loadQueue() {
if (prodId.length == 0) return;
//split the queue in parts of 10
var tmp = new Array();
while(tmp.length < 10 && prodId.length > 0) {
tmp.push(prodId.shift());
}
if (tmp.length == 0) return;
$.ajax({
url: "url_ajax",
type: "POST",
data: { "data" : prodId },
success: function(data) {
$(data).appendTo('.container');
}
});
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: mysqli::real_connect(): (hy000/2002): connection refused
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.