【发布时间】:2017-08-21 08:25:50
【问题描述】:
我正在向我的控制器发送字符串数组,其中包含 Id 数组。
function submit(){
var ids = [];
bootbox.confirm("Are you sure to 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>
控制器:
def submit(){
def result = [success:false]
if(params?.Ids){
String[] ids = params?.Ids
ids.eachWithIndex{ it, int i ->
//HERE OUTPUT IS LIKE
//4
//,
//5
//,
//6
println(it.value)
}
result["id"] = params?.Ids
}
render result as JSON
}
在 eachWithIndex 循环中,我得到了不需要的输出,(逗号),我认为必须有一个很好的选项来循环它。
请提出相同的建议。
【问题讨论】:
-
我相信这个问题应该属于codereview社区
标签: javascript arrays grails arraylist groovy