A
A
Abdulla Mursalov2015-09-18 16:01:54
JavaScript
Abdulla Mursalov, 2015-09-18 16:01:54

Similar to cycle tag in Handlebars?

Hello! Please tell me how to organize the following behavior {{#each}}:

<div class="row">
    <div class="col-sm-4">...</div>
    <div class="col-sm-4">...</div>
   <div class="col-sm-4">...</div>
</div>
<div class="row">
    <div class="col-sm-4">...</div>
    <div class="col-sm-4">...</div>
   <div class="col-sm-4">...</div>
</div>
// ...

To make div.row iterate every three iterations. Django has a similar tag that returns values ​​one by one:
{% cycle 'row1' 'row2' %}
upd. added the ember.js tag, since handlebars is a standard templating engine

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Evgeny Samsonov, 2019-04-25
@ivanmorda

Your script is executed before jQuery is initialized. wrap it in$(function() { /* здесь код */ });

$(function() {
    var top = 0, bottom = 0, left = 0, right = 0;
    $("#up").click(function() {
        top += 2;
        $("#player").css("bottom", top);
     });
});

https://jsfiddle.net/3csd9k2w/

C
Cursedproha, 2019-04-25
@Cursedproha

Everything moves, but on the first click, the value of bottom is set to zero.
Checked here:
https://jsfiddle.net/dn5x3auc/

0
0xD34F, 2019-04-25
@0xD34F

Because your variable name is top and it is global. But there can't be a global variable with that name, the place is already taken . So when you do top += 2, you are not working with a number at all. Change the name of the variable, or run your code in a scope other than the global scope, or make your top a property of some object, or...

M
Makito, 2015-09-18
@amaprograma

Write a helper that will cut off by @index of the collection

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question