playframework - Play 2 Framework + Loop for + Dynamic Javascript -
in view of play 2.4 application iterate on data, , create javascript code each iteration. javascript generated seems ok, impossible trigger event when click on button.
@for(site <- sites) { <div class="item"> <div class="item-site-pres"> <span class="item-site-title"><a href="@site.url">@site.title</a></span> </div> <div id="div@site.url" class="item-site-desc"> <center> load site <input type='button' value='+' id='input@site.url' /> </center> </div> }
javascript
<script type="text/javascript" charset="utf-8"> var load@site.url = function() { var url = @site.url; var website = @site.website; jsroutes.controllers.application.loadajax(url,website).ajax({ success: function(data) { $("#div@site.url").html(data); }, error: function() { alert("error!") } }) }; $("#input@site.url").click(load@site.url); </script>
example of div generated
<div id="divhttp://www.lequipe.fr/natation/actualites/retour-manque-pour-agnel/491210" class="item-site-desc"> <center> load site <input id="inputhttp://www.lequipe.fr/natation/actualites/retour-manque-pour-agnel/491210" type="button" value="+"> </center> </div>
example javascript generated
<script charset="utf-8" type="text/javascript"> var loadshttp://www.lequipe.fr/natation/actualites/retour-manque-pour-agnel/491210 = function() { var url = http://www.lequipe.fr/natation/actualites/retour-manque-pour-agnel/491210; var website = l'equipe.fr; jsroutes.controllers.application.loadajax(url,website).ajax({ success: function(data) { $("#divhttp://www.lequipe.fr/natation/actualites/retour-manque-pour-agnel/491210").html(data); }, error: function() { alert("error!") } }) }; $("#inputhttp://www.lequipe.fr/natation/actualites/retour-manque-pour-agnel/491210").click(loadhttp://www.lequipe.fr/natation/actualites/retour-manque-pour-agnel/491210); </script>
thank support
assuming js 1 question have fix quoting of string values, otherwise won't work.
var website = l'equipe.fr
never valid js string without wrapping value in ""
. neither syntax of var loadshttp://www.lequipe.fr/natation/actualites/retour-manque-pour-agnel/491210
ok.
Comments
Post a Comment