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,217
  • 8
  • 46
  • 68
ChristopherStrydom
  • 7,338
  • 5
  • 21
  • 34

3 Answers3

2

How about:

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

No need to invent your own serialization format.

georg
  • 211,518
  • 52
  • 313
  • 390
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
  • 74,033
  • 9
  • 94
  • 155
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
  • 142,137
  • 41
  • 261
  • 360