如何将形式params从formRemote传递给GSP中的remoteFunction

时间:2014-03-31 09:00:25

标签: grails gsp

示例非常简单。

选择两个搜索条件并返回带分页的表格,整个页面不会刷新。

所以我使用grails formRemote提交表单,控件返回带有模板的性别,它运行良好。但是,我希望使用Jquery,但我不能使用formRemote中的onSuccess方法将formRemote参数传递给remoteFunction。

这是代码:

       <div class="formSep col-md-12">

            <g:formRemote update="searchResult" class="form-inline" role="form" name="form"
                          url="[controller: 'autoRateRecord', action: 'search']" onSuccess="initPagination(data)">

                <div class="form-group col-lg-2">
                    <g:select class="form-control" name="notified" from="${['done', 'undone']}"
                              noSelection="${['null': 'Oops']}">
                    </g:select>
                </div>

                <div class="form-group col-lg-2 pull-right">
                    <button type="submit" class="btn btn-primary btn-lg">
                        <span class="glyphicon glyphicon-search"></span> search
                    </button>
                </div>

            </g:formRemote>

        </div>

        <div id="searchResult">
            <g:render template="searchList"/>
        </div>

    <script type='text/javascript'>

        function initPagination(data) {
            console.log("------> " + data)
            $("#Pagination").pagination(10, {
                callback: getRecordList(1),
                prev_text: "prev",
                next_text:  "next",
                items_per_page: 15,
                num_edge_entries: 1
            });
        }

        **!!!!!!! need formRemote data !!!!!!!**
        function getRecordList(page_index) {
            <g:remoteFunction controller="autoRateRecord" action="search" update="searchResult" params="'page='+page_index"/>
        }

        // On load, style typical form elements
        $(function () {
        });
    </script>

控制器代码是:

    def search = {
    log.info(ToStringBuilder.reflectionToString(params))
    // logic .....
    render(template: "searchList", model: [
            autoRateRecords: result,
            total          : result.totalCount
    ])
}

1 个答案:

答案 0 :(得分:0)

我会将分页脚本更改为

$("#pageHiddenFieldId").val(pageNo);
$("#myForm").submit();