Need help with cycle in JS

Posted by antiarchitect on Stack Overflow See other posts from Stack Overflow or by antiarchitect
Published on 2010-03-21T23:40:34Z Indexed on 2010/03/21 23:41 UTC
Read the original article Hit count: 346

Filed under:
|
|

I have such function, that adds a grid of droppables:

function AddClassroomDrops(grid, weeks, days, times) {
    for(week = 1; week <= weeks; week++) {
        for (day = 1; day <= days; day++) {
            for (time = 1; time <= times; time++ ) {
                Droppables.add('container_grid'+ grid + '_week' + week + '_day' + day + '_time' + time, {
                    accept: 'pair',
                    hoverclass : 'hovered_receiver',
                    onDrop: function(pair, receiver) {
                        new Ajax.Request(
                          '/pairs/'+pair.id+'/update_on_drop', {
                            method : 'put',
                            parameters : {
                              classroom : grid,
                              week : week,
                              day : day,
                              time : time,
                              container : receiver.id
                            }
                          }
                        );
                      }
                });
            }
        }
     }
}

The problem is that params of Ajax.Request (week, day, time) are always equal to weeks + 1, times + 1, days + 1. But they must vary according to the cycle.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about prototype