Meteor - #each iteration of an array with another HTML element inserted after each nth item

后端 未结 2 1052
半阙折子戏
半阙折子戏 2021-01-26 01:07

I\'m iterating over an array of items in Meteor using Blaze using the #each iterator, and I want to insert an HTML element after each nth (10th) item. I figured I could use @ind

2条回答
  •  青春惊慌失措
    2021-01-26 01:34

    You can use modulo (%), which takes the remainder of two numbers. For example 11%3 = 2, because 3 fits 3 times in 11, leaving 2 aka the remainder.

    Template.TemplateName.helpers({
        'someHelper': function(whichOne){
            if (whichOne%10 == 0){
                yourArray.push();
            }
        }
    });
    

    Whenever whichOne%10 is zero, you've hit the tenth element in your array.

提交回复
热议问题