Created
July 6, 2012 16:30
-
-
Save bradrice/3061190 to your computer and use it in GitHub Desktop.
Velocity to make json
This file contains hidden or 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
<script type="text/javascript"> | |
#set($left_b = "{") | |
#set($right_b = "}") | |
#set($colon = ":") | |
#set($comma = ",") | |
#set($ar_size = $my_id_array.size()) | |
#foreach($item in $my_id_array) | |
#set($a_i = "${quote}$item.cnt${quote}${colon}${left_b}${quote}id${quote}${colon}${quote}${item.id}${quote}${comma}${quote}urlmap${quote}${colon}${quote}${item.urlmap}${quote}${right_b}#if($velocityCount<$ar_size)${comma}#end") | |
#if($velocityCount == 1) | |
#set($my_json = "$a_i") | |
#else | |
#set($my_json = "${my_json}$a_i") | |
#end | |
#end | |
#set($final_json = "{${my_json}}") | |
var my_json = $final_json; | |
console.log(my_json[12].id); | |
var id_array_lng = id_array.length; | |
var cnt = $cnt | |
jQuery(document).ready( function() { | |
var options = {pgid_array: id_array, pgcnt: cnt} | |
Page.initialize( options ); | |
// Bind via array of elements / jQuery object | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment