grails应用程序的jquery数据表中没有填充值

grails应用程序的jquery数据表中没有填充值,jquery,grails,datatables,Jquery,Grails,Datatables,我正在从控制器操作获取一个值列表,以加载到数据表。我已检查是否已成功从控制器操作获取值,但未将值加载到数据表。它显示 没有可用的数据 这是我的控制器 package com.standout.utility应用程序 导入grails.plugin.springsecurity.annotation.securied @安全(['ROLE\u ADMIN'])) 类报表控制器{ AdminService AdminService def报告(){ println(“--内部报告控制器”); }

我正在从
控制器操作
获取一个值列表,以加载到
数据表
。我已检查是否已成功从控制器操作获取值,但未将值加载到
数据表
。它显示

没有可用的数据

这是我的控制器

package com.standout.utility应用程序
导入grails.plugin.springsecurity.annotation.securied
@安全(['ROLE\u ADMIN']))
类报表控制器{
AdminService AdminService
def报告(){
println(“--内部报告控制器”);
}
def searchAjax(){
字符串条件=参数搜索条件
println(“标准”+标准)
if(标准同等信号情况(“员工ID”)){
def resultSet=adminService.getReportById(参数)
println(“--------------------++++”+结果集)
[账单详情:结果集]
}
}

}
请尝试使用下面的代码snippest

html表
来自
gsp
文件的内容 您可以根据自己的意愿在表中添加其他自定义内容

              <table id="userDataTable" class="table table-bordered table-striped tableWidth dataTable">
                            <thead>
                            <tr>
                                <th>Branch Name</th>
                                <th>User Name</th>
                                <th>First Name</th>
                                <th>Last Name</th>
                                <th>Contact Number</th>
                            </tr>
                            </thead>
                        </table>
从这里,我们将调用控制器操作
fetchUserDetails

控制器动作
内容

    Map userDetailsMap      =   [:]

    List userDetailsList    =   userManagementService.fetchAllUsersByRestaurantId(restaurantId)

    userDetailsMap << [data : userDetailsList]

    render userDetailsMap as JSON
Map userDetailsMap=[:]
List userDetailsList=userManagementService.fetchAllUsersByRestaurantId(restaurantId)

userDetailsMap请尝试使用下面的代码snippest

html表
来自
gsp
文件的内容 您可以根据自己的意愿在表中添加其他自定义内容

              <table id="userDataTable" class="table table-bordered table-striped tableWidth dataTable">
                            <thead>
                            <tr>
                                <th>Branch Name</th>
                                <th>User Name</th>
                                <th>First Name</th>
                                <th>Last Name</th>
                                <th>Contact Number</th>
                            </tr>
                            </thead>
                        </table>
从这里,我们将调用控制器操作
fetchUserDetails

控制器动作
内容

    Map userDetailsMap      =   [:]

    List userDetailsList    =   userManagementService.fetchAllUsersByRestaurantId(restaurantId)

    userDetailsMap << [data : userDetailsList]

    render userDetailsMap as JSON
Map userDetailsMap=[:]
List userDetailsList=userManagementService.fetchAllUsersByRestaurantId(restaurantId)

userDetailsMap您在使用g:formRemote时出错 我不知道您的grails版本,但此链接提供了详细信息,您应该重视以下属性:update、onComplete

在您的情况下,我认为您应该使用onComplete事件 因为在代码中,您试图显示bill_的详细信息,但您不喜欢这样,所以在ajax调用期间会对其进行评估,但不会在代码中自动替换

使用update属性,您可以指定例如div标记的id,其中将显示ajax调用的结果

在您的情况下,您应该使用onComplete事件属性,并以JSON格式返回账单详细信息,如下所示:

def searchAjax(){
    ...
    def result = [bill_details:resultSet]
    render result as JSON
}
<g:formRemote name="billSearchForm" class="form-horizontal" onComplete="displayTable(data)" url="[controller: 'Report', action:'searchAjax']">
然后在gsp代码中指定onComplete属性,如下所示:

def searchAjax(){
    ...
    def result = [bill_details:resultSet]
    render result as JSON
}
<g:formRemote name="billSearchForm" class="form-horizontal" onComplete="displayTable(data)" url="[controller: 'Report', action:'searchAjax']">

数据将允许您访问ajax调用的JSON结果


然后,在displayTable中,您将能够迭代JSON数据bill_details

您在使用g:formRemote时出错 我不知道您的grails版本,但此链接提供了详细信息,您应该重视以下属性:update、onComplete

在您的情况下,我认为您应该使用onComplete事件 因为在代码中,您试图显示bill_的详细信息,但您不喜欢这样,所以在ajax调用期间会对其进行评估,但不会在代码中自动替换

使用update属性,您可以指定例如div标记的id,其中将显示ajax调用的结果

在您的情况下,您应该使用onComplete事件属性,并以JSON格式返回账单详细信息,如下所示:

def searchAjax(){
    ...
    def result = [bill_details:resultSet]
    render result as JSON
}
<g:formRemote name="billSearchForm" class="form-horizontal" onComplete="displayTable(data)" url="[controller: 'Report', action:'searchAjax']">
然后在gsp代码中指定onComplete属性,如下所示:

def searchAjax(){
    ...
    def result = [bill_details:resultSet]
    render result as JSON
}
<g:formRemote name="billSearchForm" class="form-horizontal" onComplete="displayTable(data)" url="[controller: 'Report', action:'searchAjax']">

数据将允许您访问ajax调用的JSON结果


然后在您的displayTable中,您将能够迭代JSON数据bill_details

,所以在controller中打印时,数据很好,对吗?如果您只需在gsp中打印出
${bill\u details.size()}
,会怎么样?它显示了什么?我认为您的gsp/jquery代码有问题。所以在控制器中打印时,数据很好,对吗?如果您只需在gsp中打印出
${bill\u details.size()}
,会怎么样?它显示了什么?我认为您的gsp/jquery代码有问题。