Partage
  • Partager sur Facebook
  • Partager sur Twitter

Problème d'initialisation/reset d'un array

    28 mars 2020 à 17:33:51

    Bonjour.

    J'essaye, via jQuery et AJAX de populer un array avec les données récupérées d'une base de donnée.

    Cela ressemble à ça:

    var $page   = $('.table').attr('data-page');
    var rawData = [];
    
    $.ajax({
        type     : 'GET',
        url      : 'get.php',
        data     : {page:$page},
        datatype : 'json',
        async    : false,
        cache    : false
    })
    .done (function(response){
    
        dataSet = JSON.parse(response);
        var col = 1, row = 2;
    
        $.each(dataSet, function(key, value){   
    
            $.each(value, function(key, value) {
                rawData[col] = [];
                rawData[col][row] = [];
                rawData[col][row][1] = key;
                rawData[col][row][2] = value;
                col++;
    
                console.log(rawData)
            }); 
    
            row++; col = 1;
        }); 
    }) 
     
    console.log(rawData)



    Le console.log du tableau à l'intérieur de la boucle me donne toutes les données (bien) alors que celui en dehors de la boucle ne me donne que la dernière rangée de données (pas bien).

    Cela est dû au fait que dans la boucle 'each", je fais ceci:

    rawData[col] = [];


    Alors, forcément, ça efface à chaque retour de boucle supérieur tout ce qui se trouvait dedans précédemment car je réinitialise le "col" à 1.
    Or, si je ne le mets pas, cela me génère un message d'erreur parce que le sous tableau n'est pas déclaré. Et je ne vois nulle part où déclarer cet array autre part pour obtenir le résultat voulu (avoir le tableau complet en dehors de la boucle) sans générer d'erreur.

    J'ai bien trouvé une solution mais elle me semble tellement pas optimale:

    var $page    = $('.table').attr('data-page');
    var rawData = [];
    
    $.ajax({
        type     : 'GET',
        url      : 'get.php',
        data     : {page:$page},
        datatype : 'json',
        async    : false,
        cache    : false
    })
    .done (function(response){
    
        dataSet = JSON.parse(response);
        var col = 1, row = 2;
    
        //Déclarer et initialiser le sub array
    
        $.each(dataSet, function(key, value){   
            $.each(value, function(key, value) {
                rawData[col] = [];
                col++;
            }); 
    
            row++; col = 1;
        }); 
    
        //Populer les array
    
        var col = 1, row = 2;
    
        $.each(dataSet, function(key, value){  
     
            $.each(value, function(key, value) {
                rawData[col][row] = [];
                rawData[col][row][1] = key;
                rawData[col][row][2] = value;
                col++;
    
                console.log(rawData)
            }); 
    
            row++; col = 1;
    
        }); 
    })  
    
    console.log(rawData)




    Là, ça marche mais je dois boucler deux fois. une fois pour initialiser les sous-tableaux et une fois pour les populer.

    Voyez-vous un moyen efficace d'obtenir le même résultat sans boucler deux fois ?

    Dans la même veine, n'existe-t-il pas un moyen simple de pouvoir déclarer un tableau du type "rawData[col]" en une fois, sans devoir boucler et déclarer chaque valeur possible de "col" ?
    Genre "rawData[] = new Array()" ou quelque chose de moins laborieux ?

    Merci.

    -
    Edité par Baylock 28 mars 2020 à 19:42:30

    • Partager sur Facebook
    • Partager sur Twitter
      28 mars 2020 à 18:39:34

      Bonjour Baylock,

      Il est possible d'avoir le json renvoyé par reponse

      • Partager sur Facebook
      • Partager sur Twitter
      Découvrez les Css avec la zonecss.fr
        28 mars 2020 à 19:32:05

        J'ai fait quelques modifs au script de départ mais l'idée est la même.

        Avec le script de base, je n'obtiens que les infos de la dernières ligne si je consulte l'array après le loop:

        [Log] Array (16)

        1 [17: [1: "Propriété", 2: "Wavre 27"]] (18)
        2 [17: [1: "Propriétaire", 2: "Lys Conseil SPRL"]] (18)
        3 [17: [1: "Type", 2: "Maison"]] (18)
        4 [17: [1: "Adresse", 2: "Chaussée de Wavre n° 27 "]] (18)
        5 [17: [1: "Commune", 2: "Etterbeek"]] (18)
        6 [17: [1: "Ville", 2: "Bruxelles"]] (18)
        7 [17: [1: "Surface", 2: "300"]] (18)
        8 [17: [1: "Chambres", 2: "4"]] (18)
        9 [17: [1: "Ascenseur", 2: "Non"]] (18)
        10 [17: [1: "Chauf ind", 2: "Non"]] (18)
        11 [17: [1: "Elec sép", 2: "Non"]] (18)
        12 [17: [1: "Eau sép", 2: "Non"]] (18)
        13 [17: [1: "Certif conf", 2: "Oui"]] (18)
        14 [17: [1: "Certif PEB", 2: "Oui"]] (18)
        15 [17: [1: "Comm", 2: "<span style=\"font-family: lato; font-size: 11px; f…ps: normal;\">Ceci est un commentaire</span></div>"]] (18)

        Avec la solution un peu poussive (double loop), j'obtiens tout si je consulte le script après le loop:

        [Log] Array (16)

        1 Array (18)
        2 [1: "Propriété", 2: "Artisans 45"] (3)
        3 [1: "Propriété", 2: "Enghien 528"] (3)
        4 [1: "Propriété", 2: "Fort Jaco 147"] (3)
        5 [1: "Propriété", 2: "Jasmin 39"] (3)
        6 [1: "Propriété", 2: "Jasmin 39"] (3)
        7 [1: "Propriété", 2: "Le Routi 4"] (3)
        8 [1: "Propriété", 2: "Maréchal 23"] (3)
        9 [1: "Propriété", 2: "Mimosas 112"] (3)
        10 [1: "Propriété", 2: "Molière 501"] (3)
        11 [1: "Propriété", 2: "Molière 501"] (3)
        12 [1: "Propriété", 2: "Molière 501"] (3)
        13 [1: "Propriété", 2: "Rabelais 301"] (3)
        14 [1: "Propriété", 2: "Tilmont 12"] (3)
        15 [1: "Propriété", 2: "Verdun 57"] (3)
        16 [1: "Propriété", 2: "Waterloo 24"] (3)
        17 [1: "Propriété", 2: "Wavre 27"] (3)

        2 Array (18)
        2 [1: "Propriétaire", 2: "Sandrine Heregots"] (3)
        3 [1: "Propriétaire", 2: "Alca invest"] (3)
        4 [1: "Propriétaire", 2: "Alca invest"] (3)
        5 [1: "Propriétaire", 2: "Lys Conseil SPRL"] (3)
        6 [1: "Propriétaire", 2: "Levaux & Co"] (3)
        7 [1: "Propriétaire", 2: "Lys Conseil SPRL"] (3)
        8 [1: "Propriétaire", 2: "Lys Conseil SPRL"] (3)
        9 [1: "Propriétaire", 2: "Levaux & Co"] (3)
        10 [1: "Propriétaire", 2: "Lys Conseil SPRL"] (3)
        11 [1: "Propriétaire", 2: "Laurent Levaux"] (3)
        12 [1: "Propriétaire", 2: "Alca invest"] (3)
        13 [1: "Propriétaire", 2: "Lys Conseil SPRL"] (3)
        14 [1: "Propriétaire", 2: "Laurent Levaux"] (3)
        15 [1: "Propriétaire", 2: "Laurent Levaux"] (3)
        16 [1: "Propriétaire", 2: "Sandrine Heregots"] (3)
        17 [1: "Propriétaire", 2: "Lys Conseil SPRL"] (3)

        3 Array (18)
        2 [1: "Type", 2: "Appartement"] (3)
        3 [1: "Type", 2: "Maison"] (3)
        4 [1: "Type", 2: "Maison"] (3)
        5 [1: "Type", 2: "Appartement"] (3)
        6 [1: "Type", 2: "Appartement"] (3)
        7 [1: "Type", 2: "Terrain agricole"] (3)
        8 [1: "Type", 2: "Maison"] (3)
        9 [1: "Type", 2: "Bureau"] (3)
        10 [1: "Type", 2: "Appartement"] (3)
        11 [1: "Type", 2: "Appartement"] (3)
        12 [1: "Type", 2: "Appartement"] (3)
        13 [1: "Type", 2: "Zone de loisirs"] (3)
        14 [1: "Type", 2: "Maison"] (3)
        15 [1: "Type", 2: "Studio"] (3)
        16 [1: "Type", 2: "Surface commerciale"] (3)
        17 [1: "Type", 2: "Maison"] (3)

        4 Array (18)
        2 [1: "Adresse", 2: "Rue des Artisans n° 45 (E2)"] (3)
        3 [1: "Adresse", 2: "Chaussée d'Enghien n° 528 "] (3)
        4 [1: "Adresse", 2: "Avenue Fort Jaco n° 147 "] (3)
        5 [1: "Adresse", 2: "Rue Louis Jasmin n° 39 (E2)"] (3)
        6 [1: "Adresse", 2: "Rue Louis Jasmin n° 39 (E1)"] (3)
        7 [1: "Adresse", 2: "Rue du Routi n° 4 "] (3)
        8 [1: "Adresse", 2: "Rue Maréchal n° 23 (E1)"] (3)
        9 [1: "Adresse", 2: "Rue des Mimosas n° 112 "] (3)
        10 [1: "Adresse", 2: "Avenue Molière n° 182 (E0)"] (3)
        11 [1: "Adresse", 2: "Avenue Molière n° 182 (E1)"] (3)
        12 [1: "Adresse", 2: "Avenue Molière n° 501 (E2)"] (3)
        13 [1: "Adresse", 2: "Rue Rabelais n° 301 "] (3)
        14 [1: "Adresse", 2: "Rue Tilmont n° 12 "] (3)
        15 [1: "Adresse", 2: "Chaussée de Verdun n° 57 (E3)"] (3)
        16 [1: "Adresse", 2: "Chaussée de Waterloo n° 24 (E1)"] (3)
        17 [1: "Adresse", 2: "Chaussée de Wavre n° 27 "] (3)

        5 Array (18)
        2 [1: "Commune", 2: "Ixelles"] (3)
        3 [1: "Commune", 2: "Watermael-Boitsfort"] (3)
        4 [1: "Commune", 2: "Uccle"] (3)
        5 [1: "Commune", 2: "Woluwé-St-Pierre"] (3)
        6 [1: "Commune", 2: "Woluwé-St-Lambert"] (3)
        7 [1: "Commune", 2: "Rochehaut"] (3)
        8 [1: "Commune", 2: "Jette"] (3)
        9 [1: "Commune", 2: "Schaerbeek"] (3)
        10 [1: "Commune", 2: "Forest"] (3)
        11 [1: "Commune", 2: "Forest"] (3)
        12 [1: "Commune", 2: "Forest"] (3)
        13 [1: "Commune", 2: "Anderlecht"] (3)
        14 [1: "Commune", 2: "Jette"] (3)
        15 [1: "Commune", 2: "Evere"] (3)
        16 [1: "Commune", 2: "Ixelles"] (3)
        17 [1: "Commune", 2: "Etterbeek"] (3)

        6 Array (18)
        2 [1: "Ville", 2: "Bruxelles"] (3)
        3 [1: "Ville", 2: "Bruxelles"] (3)
        4 [1: "Ville", 2: "Bruxelles"] (3)
        5 [1: "Ville", 2: "Bruxelles"] (3)
        6 [1: "Ville", 2: "Bruxelles"] (3)
        7 [1: "Ville", 2: "Bouillon"] (3)
        8 [1: "Ville", 2: "Bruxelles"] (3)
        9 [1: "Ville", 2: "Bruxelles"] (3)
        10 [1: "Ville", 2: "Bruxelles"] (3)
        11 [1: "Ville", 2: "Bruxelles"] (3)
        12 [1: "Ville", 2: "Bruxelles"] (3)
        13 [1: "Ville", 2: "Bruxelles"] (3)
        14 [1: "Ville", 2: "Bruxelles"] (3)
        15 [1: "Ville", 2: "Bruxelles"] (3)
        16 [1: "Ville", 2: "Bruxelles"] (3)
        17 [1: "Ville", 2: "Bruxelles"] (3)

        7 Array (18)
        2 [1: "Surface", 2: "120"] (3)
        3 [1: "Surface", 2: "350"] (3)
        4 [1: "Surface", 2: "500"] (3)
        5 [1: "Surface", 2: "80"] (3)
        6 [1: "Surface", 2: "80"] (3)
        7 [1: "Surface", 2: "1000"] (3)
        8 [1: "Surface", 2: "100"] (3)
        9 [1: "Surface", 2: "70"] (3)
        10 [1: "Surface", 2: "120"] (3)
        11 [1: "Surface", 2: "120"] (3)
        12 [1: "Surface", 2: "120"] (3)
        13 [1: "Surface", 2: "600"] (3)
        14 [1: "Surface", 2: "250"] (3)
        15 [1: "Surface", 2: "70"] (3)
        16 [1: "Surface", 2: "100"] (3)
        17 [1: "Surface", 2: "300"] (3)

        8 Array (18)
        2 [1: "Chambres", 2: "2"] (3)
        3 [1: "Chambres", 2: "4"] (3)
        4 [1: "Chambres", 2: "4"] (3)
        5 [1: "Chambres", 2: "2"] (3)
        6 [1: "Chambres", 2: "2"] (3)
        7 [1: "Chambres", 2: ""] (3)
        8 [1: "Chambres", 2: "4"] (3)
        9 [1: "Chambres", 2: ""] (3)
        10 [1: "Chambres", 2: "2"] (3)
        11 [1: "Chambres", 2: "2"] (3)
        12 [1: "Chambres", 2: "2"] (3)
        13 [1: "Chambres", 2: ""] (3)
        14 [1: "Chambres", 2: "3"] (3)
        15 [1: "Chambres", 2: "1"] (3)
        16 [1: "Chambres", 2: ""] (3)
        17 [1: "Chambres", 2: "4"] (3)

        9 Array (18)
        2 [1: "Ascenseur", 2: "Oui"] (3)
        3 [1: "Ascenseur", 2: "Non"] (3)
        4 [1: "Ascenseur", 2: "Non"] (3)
        5 [1: "Ascenseur", 2: "Non"] (3)
        6 [1: "Ascenseur", 2: "Non"] (3)
        7 [1: "Ascenseur", 2: "Non"] (3)
        8 [1: "Ascenseur", 2: "Non"] (3)
        9 [1: "Ascenseur", 2: "Oui"] (3)
        10 [1: "Ascenseur", 2: "Oui"] (3)
        11 [1: "Ascenseur", 2: "Oui"] (3)
        12 [1: "Ascenseur", 2: "Oui"] (3)
        13 [1: "Ascenseur", 2: "Non"] (3)
        14 [1: "Ascenseur", 2: "Non"] (3)
        15 [1: "Ascenseur", 2: "Oui"] (3)
        16 [1: "Ascenseur", 2: "Non"] (3)
        17 [1: "Ascenseur", 2: "Non"] (3)

        10 Array (18)
        2 [1: "Chauf ind", 2: "Oui"] (3)
        3 [1: "Chauf ind", 2: "Non"] (3)
        4 [1: "Chauf ind", 2: "Non"] (3)
        5 [1: "Chauf ind", 2: "Non"] (3)
        6 [1: "Chauf ind", 2: "Non"] (3)
        7 [1: "Chauf ind", 2: "Non"] (3)
        8 [1: "Chauf ind", 2: "Non"] (3)
        9 [1: "Chauf ind", 2: "Non"] (3)
        10 [1: "Chauf ind", 2: "Oui"] (3)
        11 [1: "Chauf ind", 2: "Oui"] (3)
        12 [1: "Chauf ind", 2: "Oui"] (3)
        13 [1: "Chauf ind", 2: "Non"] (3)
        14 [1: "Chauf ind", 2: "Non"] (3)
        15 [1: "Chauf ind", 2: "Oui"] (3)
        16 [1: "Chauf ind", 2: "Oui"] (3)
        17 [1: "Chauf ind", 2: "Non"] (3)

        11 Array (18)
        2 [1: "Elec sép", 2: "Oui"] (3)
        3 [1: "Elec sép", 2: "Non"] (3)
        4 [1: "Elec sép", 2: "Non"] (3)
        5 [1: "Elec sép", 2: "Non"] (3)
        6 [1: "Elec sép", 2: "Non"] (3)
        7 [1: "Elec sép", 2: "Non"] (3)
        8 [1: "Elec sép", 2: "Non"] (3)
        9 [1: "Elec sép", 2: "Oui"] (3)
        10 [1: "Elec sép", 2: "Oui"] (3)
        11 [1: "Elec sép", 2: "Oui"] (3)
        12 [1: "Elec sép", 2: "Oui"] (3)
        13 [1: "Elec sép", 2: "Non"] (3)
        14 [1: "Elec sép", 2: "Non"] (3)
        15 [1: "Elec sép", 2: "Oui"] (3)
        16 [1: "Elec sép", 2: "Oui"] (3)
        17 [1: "Elec sép", 2: "Non"] (3)

        12 Array (18)
        2 [1: "Eau sép", 2: "Oui"] (3)
        3 [1: "Eau sép", 2: "Non"] (3)
        4 [1: "Eau sép", 2: "Non"] (3)
        5 [1: "Eau sép", 2: "Non"] (3)
        6 [1: "Eau sép", 2: "Non"] (3)
        7 [1: "Eau sép", 2: "Non"] (3)
        8 [1: "Eau sép", 2: "Non"] (3)
        9 [1: "Eau sép", 2: "Oui"] (3)
        10 [1: "Eau sép", 2: "Oui"] (3)
        11 [1: "Eau sép", 2: "Oui"] (3)
        12 [1: "Eau sép", 2: "Oui"] (3)
        13 [1: "Eau sép", 2: "Non"] (3)
        14 [1: "Eau sép", 2: "Non"] (3)
        15 [1: "Eau sép", 2: "Non"] (3)
        16 [1: "Eau sép", 2: "Oui"] (3)
        17 [1: "Eau sép", 2: "Non"] (3)

        13 Array (18)
        2 [1: "Certif conf", 2: "Oui"] (3)
        3 [1: "Certif conf", 2: "Oui"] (3)
        4 [1: "Certif conf", 2: "Oui"] (3)
        5 [1: "Certif conf", 2: "Oui"] (3)
        6 [1: "Certif conf", 2: "Oui"] (3)
        7 [1: "Certif conf", 2: "Oui"] (3)
        8 [1: "Certif conf", 2: "Non"] (3)
        9 [1: "Certif conf", 2: "Non"] (3)
        10 [1: "Certif conf", 2: "Oui"] (3)
        11 [1: "Certif conf", 2: "Oui"] (3)
        12 [1: "Certif conf", 2: "Oui"] (3)
        13 [1: "Certif conf", 2: "Oui"] (3)
        14 [1: "Certif conf", 2: "Non"] (3)
        15 [1: "Certif conf", 2: "Oui"] (3)
        16 [1: "Certif conf", 2: "Oui"] (3)
        17 [1: "Certif conf", 2: "Oui"] (3)

        14 Array (18)
        2 [1: "Certif PEB", 2: "Oui"] (3)
        3 [1: "Certif PEB", 2: "Oui"] (3)
        4 [1: "Certif PEB", 2: "Oui"] (3)
        5 [1: "Certif PEB", 2: "Oui"] (3)
        6 [1: "Certif PEB", 2: "Oui"] (3)
        7 [1: "Certif PEB", 2: "Oui"] (3)
        8 [1: "Certif PEB", 2: "Non"] (3)
        9 [1: "Certif PEB", 2: "Non"] (3)
        10 [1: "Certif PEB", 2: "Oui"] (3)
        11 [1: "Certif PEB", 2: "Oui"] (3)
        12 [1: "Certif PEB", 2: "Oui"] (3)
        13 [1: "Certif PEB", 2: "Non"] (3)
        14 [1: "Certif PEB", 2: "Non"] (3)
        15 [1: "Certif PEB", 2: "Oui"] (3)
        16 [1: "Certif PEB", 2: "Oui"] (3)
        17 [1: "Certif PEB", 2: "Oui"] (3)

        15 Array (18)
        2 [1: "Comm", 2: ""] (3)
        3 [1: "Comm", 2: ""] (3)
        4 [1: "Comm", 2: "Ceci est un commentaire<div><span style=\"font-fami…ps: normal;\">Ceci est un commentaire</span></div>"] (3)
        5 [1: "Comm", 2: "<span style=\"font-family: lato; font-size: 11px; f…caps: normal;\">Ceci est un commentaire</span><br>"] (3)
        6 [1: "Comm", 2: ""] (3)
        7 [1: "Comm", 2: ""] (3)
        8 [1: "Comm", 2: ""] (3)
        9 [1: "Comm", 2: "Ceci est un commentaire"] (3)
        10 [1: "Comm", 2: "<span style=\"font-family: lato; font-size: 11px; f…ps: normal;\">Ceci est un commentaire</span></div>"] (3)
        11 [1: "Comm", 2: "<span style=\"font-family: lato; font-size: 11px; f…caps: normal;\">Ceci est un commentaire</span><br>"] (3)
        12 [1: "Comm", 2: "<span style=\"font-family: lato; font-size: 11px; f…ps: normal;\">Ceci est un commentaire</span></div>"] (3)
        13 [1: "Comm", 2: "<span style=\"font-family: lato; font-size: 11px; f…ps: normal;\">Ceci est un commentaire</span></div>"] (3)
        14 [1: "Comm", 2: "<span style=\"font-family: lato; font-size: 11px; f…caps: normal;\">Ceci est un commentaire</span><br>"] (3)
        15 [1: "Comm", 2: "<span style=\"font-family: lato; font-size: 11px; f…caps: normal;\">Ceci est un commentaire</span><br>"] (3)
        16 [1: "Comm", 2: "<span style=\"font-family: lato; font-size: 11px; f…caps: normal;\">Ceci est un commentaire</span><br>"] (3)
        17 [1: "Comm", 2: "<span style=\"font-family: lato; font-size: 11px; f…ps: normal;\">Ceci est un commentaire</span></div>"] (3)

        Je ne sais pas si c'est le formatage que tu voulais mais en tous cas c'est le retour de console.

        -
        Edité par Baylock 28 mars 2020 à 19:44:44

        • Partager sur Facebook
        • Partager sur Twitter
          29 mars 2020 à 11:01:40

          Bonjour Baylock,

          Il me faut le Json pour voir sa structure et afin de comprendre ce que tu fais

          • Partager sur Facebook
          • Partager sur Twitter
          Découvrez les Css avec la zonecss.fr
            30 mars 2020 à 15:09:33


            [Log] "[{\"Propriété\":\"Artisans 45\",\"Propriétaire\":\"Sandrine Heregots\",\"Type\":\"Appartement\",\"Adresse\":\"Rue des Artisans n° 45 (E2)\",\"Commune\":\"Ixelles\",\"Ville\":\"Bruxelles\",\"Surface\":\"120\",\"Chambres\":\"2\",\"Ascenseur\":\"Oui\",\"Chauf ind\":\"Oui\",\"Elec sép\":\"Oui\",\"Eau sép\":\"Oui\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Oui\",\"Comm\":\"\"},{\"Propriété\":\"Enghien 528\",\"Propriétaire\":\"Alca invest\",\"Type\":\"Maison\",\"Adresse\":\"Chaussée d'Enghien n° 528 \",\"Commune\":\"Watermael-Boitsfort\",\"Ville\":\"Bruxelles\",\"Surface\":\"350\",\"Chambres\":\"4\",\"Ascenseur\":\"Non\",\"Chauf ind\":\"Non\",\"Elec sép\":\"Non\",\"Eau sép\":\"Non\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Oui\",\"Comm\":\"\"},{\"Propriété\":\"Fort Jaco 147\",\"Propriétaire\":\"Alca invest\",\"Type\":\"Maison\",\"Adresse\":\"Avenue Fort Jaco n° 147 \",\"Commune\":\"Uccle\",\"Ville\":\"Bruxelles\",\"Surface\":\"500\",\"Chambres\":\"4\",\"Ascenseur\":\"Non\",\"Chauf ind\":\"Non\",\"Elec sép\":\"Non\",\"Eau sép\":\"Non\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Oui\",\"Comm\":\"Ceci est un commentaire<div><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><br><\\/div><div><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><\\/div>\"},{\"Propriété\":\"Jasmin 39\",\"Propriétaire\":\"Lys Conseil SPRL\",\"Type\":\"Appartement\",\"Adresse\":\"Rue Louis Jasmin n° 39 (E2)\",\"Commune\":\"Woluwé-St-Pierre\",\"Ville\":\"Bruxelles\",\"Surface\":\"80\",\"Chambres\":\"2\",\"Ascenseur\":\"Non\",\"Chauf ind\":\"Non\",\"Elec sép\":\"Non\",\"Eau sép\":\"Non\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Oui\",\"Comm\":\"<span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><br>\"},{\"Propriété\":\"Jasmin 39\",\"Propriétaire\":\"Levaux & Co\",\"Type\":\"Appartement\",\"Adresse\":\"Rue Louis Jasmin n° 39 (E1)\",\"Commune\":\"Woluwé-St-Lambert\",\"Ville\":\"Bruxelles\",\"Surface\":\"80\",\"Chambres\":\"2\",\"Ascenseur\":\"Non\",\"Chauf ind\":\"Non\",\"Elec sép\":\"Non\",\"Eau sép\":\"Non\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Oui\",\"Comm\":\"\"},{\"Propriété\":\"Le Routi 4\",\"Propriétaire\":\"Lys Conseil SPRL\",\"Type\":\"Terrain agricole\",\"Adresse\":\"Rue du Routi n° 4 \",\"Commune\":\"Rochehaut\",\"Ville\":\"Bouillon\",\"Surface\":\"1000\",\"Chambres\":\"\",\"Ascenseur\":\"Non\",\"Chauf ind\":\"Non\",\"Elec sép\":\"Non\",\"Eau sép\":\"Non\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Oui\",\"Comm\":\"\"},{\"Propriété\":\"Maréchal 23\",\"Propriétaire\":\"Lys Conseil SPRL\",\"Type\":\"Maison\",\"Adresse\":\"Rue Maréchal n° 23 (E1)\",\"Commune\":\"Jette\",\"Ville\":\"Bruxelles\",\"Surface\":\"100\",\"Chambres\":\"4\",\"Ascenseur\":\"Non\",\"Chauf ind\":\"Non\",\"Elec sép\":\"Non\",\"Eau sép\":\"Non\",\"Certif conf\":\"Non\",\"Certif PEB\":\"Non\",\"Comm\":\"\"},{\"Propriété\":\"Mimosas 112\",\"Propriétaire\":\"Levaux & Co\",\"Type\":\"Bureau\",\"Adresse\":\"Rue des Mimosas n° 112 \",\"Commune\":\"Schaerbeek\",\"Ville\":\"Bruxelles\",\"Surface\":\"70\",\"Chambres\":\"\",\"Ascenseur\":\"Oui\",\"Chauf ind\":\"Non\",\"Elec sép\":\"Oui\",\"Eau sép\":\"Oui\",\"Certif conf\":\"Non\",\"Certif PEB\":\"Non\",\"Comm\":\"Ceci est un commentaire\"},{\"Propriété\":\"Molière 501\",\"Propriétaire\":\"Lys Conseil SPRL\",\"Type\":\"Appartement\",\"Adresse\":\"Avenue Molière n° 182 (E0)\",\"Commune\":\"Forest\",\"Ville\":\"Bruxelles\",\"Surface\":\"120\",\"Chambres\":\"2\",\"Ascenseur\":\"Oui\",\"Chauf ind\":\"Oui\",\"Elec sép\":\"Oui\",\"Eau sép\":\"Oui\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Oui\",\"Comm\":\"<span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><br><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><\\/div>\"},{\"Propriété\":\"Molière 501\",\"Propriétaire\":\"Laurent Levaux\",\"Type\":\"Appartement\",\"Adresse\":\"Avenue Molière n° 182 (E1)\",\"Commune\":\"Forest\",\"Ville\":\"Bruxelles\",\"Surface\":\"120\",\"Chambres\":\"2\",\"Ascenseur\":\"Oui\",\"Chauf ind\":\"Oui\",\"Elec sép\":\"Oui\",\"Eau sép\":\"Oui\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Oui\",\"Comm\":\"<span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><br>\"},{\"Propriété\":\"Molière 501\",\"Propriétaire\":\"Alca invest\",\"Type\":\"Appartement\",\"Adresse\":\"Avenue Molière n° 501 (E2)\",\"Commune\":\"Forest\",\"Ville\":\"Bruxelles\",\"Surface\":\"120\",\"Chambres\":\"2\",\"Ascenseur\":\"Oui\",\"Chauf ind\":\"Oui\",\"Elec sép\":\"Oui\",\"Eau sép\":\"Oui\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Oui\",\"Comm\":\"<span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><br><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><\\/div>\"},{\"Propriété\":\"Rabelais 301\",\"Propriétaire\":\"Lys Conseil SPRL\",\"Type\":\"Zone de loisirs\",\"Adresse\":\"Rue Rabelais n° 301 \",\"Commune\":\"Anderlecht\",\"Ville\":\"Bruxelles\",\"Surface\":\"600\",\"Chambres\":\"\",\"Ascenseur\":\"Non\",\"Chauf ind\":\"Non\",\"Elec sép\":\"Non\",\"Eau sép\":\"Non\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Non\",\"Comm\":\"<span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><br><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><\\/div>\"},{\"Propriété\":\"Tilmont 12\",\"Propriétaire\":\"Laurent Levaux\",\"Type\":\"Maison\",\"Adresse\":\"Rue Tilmont n° 12 \",\"Commune\":\"Jette\",\"Ville\":\"Bruxelles\",\"Surface\":\"250\",\"Chambres\":\"3\",\"Ascenseur\":\"Non\",\"Chauf ind\":\"Non\",\"Elec sép\":\"Non\",\"Eau sép\":\"Non\",\"Certif conf\":\"Non\",\"Certif PEB\":\"Non\",\"Comm\":\"<span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><br>\"},{\"Propriété\":\"Verdun 57\",\"Propriétaire\":\"Laurent Levaux\",\"Type\":\"Studio\",\"Adresse\":\"Chaussée de Verdun n° 57 (E3)\",\"Commune\":\"Evere\",\"Ville\":\"Bruxelles\",\"Surface\":\"70\",\"Chambres\":\"1\",\"Ascenseur\":\"Oui\",\"Chauf ind\":\"Oui\",\"Elec sép\":\"Oui\",\"Eau sép\":\"Non\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Oui\",\"Comm\":\"<span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><br>\"},{\"Propriété\":\"Waterloo 24\",\"Propriétaire\":\"Sandrine Heregots\",\"Type\":\"Surface commerciale\",\"Adresse\":\"Chaussée de Waterloo n° 24 (E1)\",\"Commune\":\"Ixelles\",\"Ville\":\"Bruxelles\",\"Surface\":\"100\",\"Chambres\":\"\",\"Ascenseur\":\"Non\",\"Chauf ind\":\"Oui\",\"Elec sép\":\"Oui\",\"Eau sép\":\"Oui\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Oui\",\"Comm\":\"<span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><br>\"},{\"Propriété\":\"Wavre 27\",\"Propriétaire\":\"Lys Conseil SPRL\",\"Type\":\"Maison\",\"Adresse\":\"Chaussée de Wavre n° 27 \",\"Commune\":\"Etterbeek\",\"Ville\":\"Bruxelles\",\"Surface\":\"300\",\"Chambres\":\"4\",\"Ascenseur\":\"Non\",\"Chauf ind\":\"Non\",\"Elec sép\":\"Non\",\"Eau sép\":\"Non\",\"Certif conf\":\"Oui\",\"Certif PEB\":\"Oui\",\"Comm\":\"<span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><br><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><br><\\/span><\\/div><div style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\"><span style=\\\"font-family: lato; font-size: 11px; font-style: normal; font-variant-caps: normal;\\\">Ceci est un commentaire<\\/span><\\/div>\"}]" (script.js, line 40)

            -
            Edité par Baylock 30 mars 2020 à 15:29:43

            • Partager sur Facebook
            • Partager sur Twitter
              30 mars 2020 à 15:28:32

              Bonjour,

              L'erreur me parait logiquen tu essaye d'avoir un tableau avec 2 indexes (enfin 3, mais le 3e index n'a que les valeurs 1 et on n'en tiendra pas compte) donc la bonne logique serait celle-ci:

                  $.each(dataSet, function(key, value){  
              
                      // nouvelle colonne 
                      rawData[col] = [];
              
                      $.each(value, function(key, value2) {
              
                          // nouvelle ligne
                          rawData[col][row] = [];
                          rawData[col][row][1] = key;
                          rawData[col][row][2] = value2;
              
                          row++;
                          console.log(rawData)
                      });
              
                      col++;
                
                  });
                  

              en plus, tu a 2 variables "value" avec risque de collision, j'en ai renommé une = value2 ... au cas où  ;) 

              • Partager sur Facebook
              • Partager sur Twitter

              Problème d'initialisation/reset d'un array

              × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
              × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
              • Editeur
              • Markdown