J'ai un tableau multi-dimensionnel nommé graph en PHP que j'ai envoyé au fichier smarty.tpl et je l'obtiens en tpl au nom de smarty variable graph.Conversion d'un tableau smary multidimensionnel en un tableau multidimensionnel Javascript
Array
(
[0] => Array
(
[weight] => 950.500
[date] => 27
)
[1] => Array
(
[weight] => 800.100
[date] => 31
)
[2] => Array
(
[weight] => 250.250
[date] => 03
)
)
Maintenant, je voudrais créer un tableau multidimensionnel dans javascript dans ce tpl. Comment puis je faire ça ?
echo json_encode($graph);
$smarty -> assign("graph",$graph);
$smarty -> assign("data_weight",$data_weight);
et à l'intérieur fichier tpl Je suis en train d'obtenir le tableau dans ce format
var d1 = [[1,100], [2,110], [3,99], [4,114]];
J'ai essayé cette commande pour convertir objet JSON tableau
var d1 = JSON.parse(JSON.stringify(graph));
Mais c'est ne fonctionne pas.
Ce n'est pas un problème de javascript, c'est lié à PHP –
Trouvé la solution ?? –
Copie possible de [convertir tableau smarty en tableau javascript] (http://stackoverflow.com/questions/16847114/convert-smarty-array-to-javascript-array) – Sheepy