Using Jquery.js
在script里写上jquery的Ajax 注意#'''' 都是tag的id
<script>
$(document).ready(function() {
$("#selectGroup").change(function() { //对selectGroup的change做响应
$.ajax({
url: "/TaskManager/testProject/groupChange", //响应到那个处理 对应到controller的函数
data: "id=" + this.value,
cache: false,
success: function(html) {$("#selectbody").html(html)} //对selectbody部分做html替换
});
});
});
</script>
def groupChange = {
def tempList = TestProject.findAll("from TestProject as b where b.createBy.username=?",[request.getRemoteUser()]).toList()
for(int i=0;i<tempList.size();i++)
{
render("<tr class='${(i % 2) == 0 ? 'odd' : 'even'}'><td><a href='/TaskManager/testProject/show/${tempList[i].id}'>${tempList[i].projectName}</a></td><td>${tempList[i].projectDescription}</td><td>${request.getRemoteUser()}</td></tr>")//返回的是html
}
}
//也可以返回标签 但是是g.select之类 而且不能返回逻辑标签
render g.select(from:module.testCases.grep{it.runnable==true},id: 'testCase', name: "testCase",size:20, style:"width:400")
Jquery直接当javascript更方便
<script>
$(document).ready(function() {
$("#selectGroup").change(function() {
if(this.value=="MyProject")
window.location.assign("${createLink(controller:'testProject', action:'listuser')}")
if(this.value=="AllProject")
window.location.assign("${createLink(controller:'testProject', action:'listAll')}")
if(this.value=="GroupProject")
window.location.assign("${createLink(controller:'testProject', action:'list')}")
});
});
</script>
window.location.href 在浏览器中就是完整的地址栏
window.location.protocol URL 的协议部分
window.location.host URL 的主机部分
window.location.port URL 的端口部分
window.location.pathname URL 的路径部分(就是文件地址)
window.location.search 查询(参数)部分