gpt4 book ai didi

jquery - BootStrap.groovy数据到gsp中的jqGrid中(groovy服务器页面)

转载 作者:行者123 更新时间:2023-12-02 14:51:43 27 4
gpt4 key购买 nike

如何在gsp页面中将BootStrap数据填充到jqGrid布局中
我需要使用BootStrap类在gsp页面上显示所有静态数据,然后相应地创建webservice。

我正在使用Grails 2.3.8,GGTS 3.5.1,jdk 1.7。

BootStrap.groovy文件:

class BootStrap {

def init = { servletContext ->
// if we have an empty customer database,
// create some test data
if (Customer.count() == 0) {
new Customer(
firstName:'John', lastName:'Smith',
age:27,
emailAddress:'john@somewhere.com'
).save()
// and so on
}
}

def destroy = { }

}

域类:
class Customer {
String firstName
String lastName
Integer age
String emailAddress
}

Controller 类:
class CustomerController {

// return JSON list of customers
def jq_customer_list = {
def customers = Customer.list()
def jsonCells = customers.collect {
[cell: [it.firstName,
it.lastName,
it.age,
it.emailAddress
], id: it.id]
}
def jsonData= [rows: jsonCells]
render jsonData as JSON
}
}

gsp文件:
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<meta name="layout" content="main"/>
<link rel="stylesheet" href="${resource(dir:'css',file:'main.css')}" />
<link rel="stylesheet" href="${resource(dir:'css',file:'ui.jqgrid.css')}" />
<link rel="stylesheet" href="${resource(dir:'css/ui-lightness',file:'jquery-ui-1.7.2.custom.css')}" />
<g:javascript src="jquery-1.3.2.min.js"/>
<g:javascript src="jquery-ui-1.7.2.custom.min.js"/>
<g:javascript src="grid.locale-en.js"/>
<g:javascript src="jquery.jqGrid.min.js"/>

<title>Customer list</title>
</head>
<body>
<div class="body">
<h1>Customer List</h1>

<!-- table tag will hold our grid -->
<table id="customer_list" class="scroll jqTable" cellpadding="0" cellspacing="0">

</table>
<!-- pager will hold our paginator -->
<div id="customer_list_pager" class="scroll" style="text-align:center;"></div>

<script type="text/javascript">
/* when the page has finished loading.. execute the follow */
$(document).ready(function () {
jQuery("#customer_list").jqGrid({
url:'jq_customer_list',
datatype: "json",
colNames:['First Name','Last Name','Age','Email Address','id'],
colModel:[
{name:'firstName'},
{name:'lastName'},
{name:'age'},
{name:'email'},
{name:'id'}
],
pager: jQuery('#customer_list_pager'),
viewrecords: true,
gridview: true
});
});
</script>

</div>
</body>
</html>

最佳答案

我不是jqgrid的专家,但是我可以想象出您的问题的以下解决方案:

$(document).ready(function () {
jQuery("#customer_list").jqGrid({
url:'${g.createLink( controller:'customer', action:'jq_customer_list' )}',
...

关于jquery - BootStrap.groovy数据到gsp中的jqGrid中(groovy服务器页面),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25445321/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com