Created
September 14, 2014 09:47
-
-
Save RaphaelBlehoue/3aa912196eb832d7ecb3 to your computer and use it in GitHub Desktop.
Bonjour j'utilise Mustache et j'aimerai afficher mes données recuperées en ajax avec le template mustache , mais je ne compren pas pourquoi celui ne s'affiche pas : Voila mon code - j'utilise cakephp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//données recuperées en JSON | |
[ | |
{ | |
"User": { | |
"lastname": "wild", | |
"firstname": "bertrand", | |
"email": "wild@outlook.fr", | |
"entreprise": "alpha", | |
"fonction": "ScrumMaster" | |
} | |
}, | |
{ | |
"User": { | |
"lastname": "micheal", | |
"firstname": "jhon", | |
"email": "johnd@outlook.fr", | |
"entreprise": "beta", | |
"fonction": "developer" | |
} | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Chargement du fichier JS et code pour afficher les données avec template Mustache | |
<?php echo $this->Html->script('mustache',array('inline'=>false)); ?> | |
$(window).load(function(){ | |
var url = '<?php echo $this->Html->url(array('controller' => 'Users','action' => 'getuser')); ?>'; | |
var tpl; | |
$.get(url,{},function(data){ | |
$('#loading').hide(); | |
var tpl = $("#tpluser").html(); | |
var htmls = Mustache.render(tpl, data); | |
$("#member").append(htmls); | |
},"json"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Template Mustache | |
<div class="hidden" id="tpluser"> | |
{{#User}} | |
<h1>{{lastname}} {{firstname}}</h1> | |
<span>{{fonction}}</span> | |
<span>{{email}}</span> | |
{{/User}} | |
</div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Avec cette structure de donnée ça devrait mieux marcher je pense.