0

Why is var test = positions.join("/"); returning [object Object]/[object Object]/[object Object] and so on? what needs to be changed in-order for this to work properly?

It should be returning positions like 0,0/0,360/0,660. Im not sure if the commas would be in there though.

$(function() {
    $('.AppList').droppable({
        accept: ".App",
        tolerance: 'fit',
        drop: function(event, ui) {
            var apps = $(".App"),
            positions = [];

            $.each(apps, function (index, app) {
                var positionInfo = $(app).position();

                positions.push(positionInfo);
            });
            var test = positions.join("/");
            console.log(test);
        }
    }); 
});
Amit
  • 15,021
  • 8
  • 44
  • 66
ChristopherStrydom
  • 6,198
  • 5
  • 19
  • 34

3 Answers3

2

How about:

var test = JSON.stringify(positions);
console.log(test);

No need to invent your own serialization format.

georg
  • 204,715
  • 48
  • 286
  • 369
1

You are returning object from function position(). Try this instead:

 $.each(apps, function (index, app) {
           var pos =  $(app).position(),   
               positionInfo = pos.top+","+ pos.left;

            positions.push(positionInfo);
        });
A. Wolff
  • 73,242
  • 9
  • 90
  • 149
0

The Array.join() method returns a string. Since your array items are objects you can't expect anything particularly useful—[object Object] is what JavaScript creates as default when casting objects to strings.

Álvaro González
  • 135,557
  • 38
  • 250
  • 339