javascript - Best way to loop through arraylist in grails -
i'm sending string array controller contains array of ids in it.
function submit(){ var ids = []; bootbox.confirm("are sure send data?", function(confirmed){ if(confirmed){ $('input[id^="tdcheckbox_"]').each( function () { var $this = $(this); if($this.is(":checked")){ ids.push($this.attr("id").replace("tdcheckbox_","")); } } ); $("#ids").val(ids); $("#submitform").submit(); } }); } <g:formremote name="submitform" url="[controller:'mycontroller', action:'submit']" onsuccess="removeids(data)"> <g:hiddenfield name="ids" /> </g:formremote> controller:
def submit(){ def result = [success:false] if(params?.ids){ string[] ids = params?.ids ids.eachwithindex{ it, int -> //here output //4 //, //5 //, //6 println(it.value) } result["id"] = params?.ids } render result json } in eachwithindex loop i'm getting output , (comma) not require, think there must option loop through it.
please suggest same.
problem submitting javascript 1 string value (ids delimited coma)
ids=1,2,33 and on level of groovy/grails params?.ids returns string this: "1,2,33"
and assigning string string[] splits chars...
as workaround in groovy can use params?.ids?.split(',')
string[] ids = "1,2,33".split(',') or submit multiple values form javascript this:
ids=1 & ids=2 & ids=33 in case grails return array params?.ids expression if more 1 value submitted same name
Comments
Post a Comment