javascript - HTML concatenation issues in JS -
i trying make dynamic html i'll append using jquery before append if i'll console html looks fine after append in browser whole structure messed up.
here html :
<script> var title = "my title"; var toolbar ='<hm_toolbar user="current_user " upp="hm" index="hmindex "></hm><synapse_toolbar uuid=" hm.hm_pk " my-method="get_linked_facts" ng-if=" flag == true "></synapse_toolbar>'; var map_html = '<a onclick="pantomarker(' + lat + ',' + long + ')"> ' + title +'"</a>' + toolbar ; var li_html = "$('#" + title + "').append('<li class=\"list-group-item\"><div dynamic=\" " + map_html + " \"></div></li> ')" ; var g =title.replace(/ /g,"_");; var fn = "function "+ g +"(){ console.log('--working--'); "+ li_html +"; }"; console.log(fn) eval(fn); } </script>
when above li_html work means append html appended messed
appended html :
<li class="list-group-item"><div pantomarker(49.711083,6.251445)"="" dynamic=" <a onclick="> test"<hm_toolbar index="hmindex " upp="hm" user="current_user "></hm_toolbar><synapse_toolbar ng-if=" flag == true " my-method="get_linked_facts" uuid=" hm.hm_pk "></synapse_toolbar> "></div></li>
i know have messed concatenation using quotes not able fixed bug .
you said console.log()
looks ok have eval()
after means have escape quotes twice.
try this:
var toolbar ='<hm_toolbar user=\\\'current_user \\\' upp=\\\'hm\\\' index=\\\'hmindex \\\'></hm><synapse_toolbar uuid=\\\' hm.hm_pk \\\' my-method=\\\'get_linked_facts\\\' ng-if=\\\' flag == true \\\'></synapse_toolbar>'; var map_html = '<a onclick=\\\'pantomarker(' + lat + ',' + long + ')\\\'> ' + title +'</a>' + toolbar ;
Comments
Post a Comment