No sorting in Array, for whatever I try
I've got following code and I dunno why the hell the output won't get sorted, as I will explain further on:
-
- /*
- Author: Jennifer Eberlei
- Project: World-Map
- Date: 06-02-2013 // 07-02-2013
- */
-
- $(document).ready(function() {
-
- function getWorldMapCoordinates() {
- var arr = new Array();
- arr = [
- {
- name: "Deutschland",
- numPosts: 14,
- coordinates: {
- x: 50,
- y: 50
- },
- link: "http://google.de/search?q=deutschland"
- },
- {
- name: "Albanien",
- numPosts: 33,
- coordinates: {
- x: 65,
- y: 30
- },
- link: "http://google.de/search?q=albanien"
- },
- {
- name: "Saudi-Arabien",
- numPosts: 126,
- coordinates: {
- x: 55,
- y: 70
- },
- link: "http://google.de/search?q=saudi-arabien"
- },
- {
- name: "China",
- numPosts: 33,
- coordinates: {
- x: 30,
- y: 35
- },
- link: "http://google.de/search?q=china"
- }
- ];
-
-
- // Füge Wrapper hinzu
- $('body').prepend($('<div id="world-map-content">'));
-
- $.each(arr, function(key, value) {
- // Create Objects
- $link = value.link;
- $name = value.name;
- $coords_x = value.coordinates.x;
- $coords_y = value.coordinates.y;
- $num = value.numPosts;
- $newsize = $num * 1.5;
- $margin = $newsize * 0.5;
-
-
- // make new array of numPosts
-
- var maxi = new Array();
- maxi = [
- anzahl = $num
- ];
-
-
- var maxi2 = maxi.anzahl;
-
- $newew = maxi2.sort();
- console.log($newew);
- $new = maxi.sort(function(b, a) {
- var a = anzahl;
- var b = anzahl;
- return a > b ? 1 : a < b ? -1 : 0;
- });
- console.log($new);
-
-
- // Do some Markup
- $('#world-map-content').append(
- $('<div class="world-map-entry ' + [key] + '"><div class="world-map-entry-bg" style="left:' + $coords_x + '%; top:' + $coords_y + '%; width:' + $newsize + 'px; height: ' + $newsize + 'px; margin-left: -' + $margin + 'px; margin-top: -' + $margin + 'px;"><img class="world-map-entry-circle" style="width:' + $newsize + 'px;height="' + $newsize + 'px;" src="img/circle.png" /></div>')
- // Styles for reuse
- // style="left: 50%; top: 50%; width: 100px; height: 100px; margin-left: -50px; margin-top: -50px;"
- );
- $('.'+ key + '').append('<div class="world-map-entry-text" style="left:' + $coords_x + '%; top:' + $coords_y + '%; width:' + $newsize + 'px; height: ' + $newsize + 'px; margin-left: -' + $margin + 'px; margin-top: 0px;" ><a href="' + $link +'" title="' + $name + '">' + $name + '</a></div></div>');
-
- });
-
-
- // +++ End Schleife +++
- // $('body').append($('</div>'));
- }
- // sort please
-
-
-
-
-
-
- // +++ End of sorting
-
-
-
-
-
- getWorldMapCoordinates();
- });
So well, I want the numPosts in Array to be sorted descending as I need it for setting up a z-index to the .each() option, because I want to display further on somekinda world-map with circles, which can be overlayed by each other. They will've got different sizes, so I'll need the option to display smaller circles above bigger circles.
I'm open to any suggestions and questions