jeudi 8 février 2018

Display correctly an array of array within js code using blade

Under my Laravel controller I have to arrays:

$labels   = [6,7,8,9,10,11,12,13,14,15,16];

$datasets = [{
              "label": "Chiron",
              "backgroundColor": "#65e4ff",
              "borderColor": "#65e4ff",
              "data": [0.297619047619, 0.925595238095, 1, 
               0.886904761905, 0.902678571429, 0.993650793651, 
               0.925595238095, 0.915277777778, 0.97619047619, 0.920634920635]
             }];

When I pass those php arrays to my view using blade $label will work fine but not $datasets

var barChartData = {
    labels: ,
    datasets: 
};

With the following error :

Uncaught SyntaxError: Unexpected token &

The code source of the page shows :

datasets:[{"label":"Chiron&quot...

However, doing :

var barChartData = {
    labels: ,
    datasets:<?php echo json_encode($datasets); ?>
};

works like a charm. How could I correctly use blade to achieve the same result?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire