削除するフィールドを選択する必要がある grails プロジェクトがあり、削除をクリックすると、選択したすべての項目を削除する関数が必要です。
html コード:
<form name="bookForm" action="list" method="post">
....
<a onclick="deleteBooks();">Delete</a>
....
....
<g:checkBox id="select_all" name="select_all" value="" onclick="selectAll();" />
....
<g:each in="${bookList}" status="i" var="bookInstance">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<td><g:checkBox id="${bookInstance.id}" name="delete_checkbox" value="" /></td>
</tr>
</g:each>
....
</form>
JavaScript コード:
<script type="text/javascript">
function selectAll(){
var select = document.getElementById("select_all");
var checkboxes = document.forms['bookForm'].elements['delete_checkbox'];
if (select.checked){
for (i = 0; i < checkboxes.length; i++) checkboxes[i].checked = true;
}else{
for (i = 0; i < checkboxes.length; i++) checkboxes[i].checked = false;
}
}
function deleteBooks(){
var checkboxes = document.forms['bookForm'].elements['delete_checkbox'];
var counter = 0;
for (i = 0; i < checkboxes.length; i++){
if(checkboxes[i].checked){
counter ++;
${g.remoteFunction(action:'delete', controller:'book', id:checkboxes[i].id) }
}
}
if (counter == 0) alert("select books to delete");
}
</script>
selectAll関数は正常に動作しますが、追加するとdeleteBooks関数がこのエラーを引き起こします
${g.remoteFunction(action:'delete', controller:'book', id:checkboxes[i].id) }
例外:
Error 500: Error evaluating expression [g.remoteFunction(action:'delete', controller:'book', id: checkboxes[i].id)] on line [26]: Cannot get property 'null' on null object
Servlet: grails
URI: /myProject/grails/book/list.dispatch
Exception Message: Cannot get property 'null' on null object
Caused by: Error evaluating expression [g.remoteFunction(action:'delete', controller:'book', id: checkboxes[i].id)] on line [26]: Cannot get property 'null' on null object
Class: list.gsp
At Line: [26]
Code Snippet:
そして、それを置き換えると${g.remoteFunction(action:'delete', controller:'book') }
例外:
Error 500: Error evaluating expression [g.remoteFunction(action:'delete', controller:'book')] on line [27]: No javascript provider is configured
Servlet: grails
URI: /myProject/grails/book/list.dispatch
Exception Message: No javascript provider is configured
Caused by: Error evaluating expression [g.remoteFunction(action:'delete', controller:'book')] on line [27]: No javascript provider is configured
Class: list.gsp
At Line: [27]
Code Snippet:
javascript関数またはjqueryからコントローラーアクションを呼び出すにはどうすればよいですか?