0

我有一个使用 twitter 引导程序的弹出窗口,然后我有一个调用控制器操作的 javascript。在该控制器操作上,我渲染一个字符串以显示在弹出窗口中。在那个动作上,我有另一个渲染,它渲染 gsp 页面本身,因为在 textarea 中添加了一个值。如何使第二次渲染工作?

普惠制:

          <g:javascript>
        function callEgCreate(){
          $.ajax({
          type: "GET",
          url: "${createLink(controller: 'MGExecutingGroup', action: 'addEG_Create')}",
          data: {
                    "inputField="+$("[name='inputField']").val()
                    "listField="+$("[name='listField']").val()
          }
            }).success(function(data) {
                $('.modal-body').html(data);
                $('#myModal').modal('show');
            });
        }
      </g:javascript>

       <g:textField name="inputField" />
      <!-- Button to trigger modal -->
      <a href="javascript:void(0)" class="btn" onclick="callEgCreate()">+</a>


      <!-- Modal -->
      <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
          <h3 id="myModalLabel">Members</h3>
        </div>
        <div class="modal-body">
        </div>
      </div>
      <textArea name="listField" id="listField" rows="50" cols="6" readonly>${params.Result}</textarea></td>

控制器:

def addEG_Create = {
    def LdapName
    def result
    def membersString = ''
    def members = ''
    result = proxy.getWLSGroupParticipants(params.inputField)
    if(result != null){
        params.egId = params.id
        LdapName = proxy.getWLSGroupsForUser(result[0])
        int index
        if (LdapName.size()>1){
            index = 0
            //find the index number for the correct Ldap name
            for (int i = 0; i < LdapName.size(); i++) {
                if (LdapName[i].toUpperCase() == params.inputField.toUpperCase()){
                    index = i
                }
            }
        }else{
            index = 0
        }
        if(params.listField.find(LdapName[index])){
            params.Result = params.listField.trim()
            membersString = params.listField.replace('\n',',')
            flash.message = params.inputField + " exist in the list!"
        }else{
            flash.message = ""
            if(params.listField!=''){
                if(params.listField.charAt(params.listField.length()-1)=='\n'){
                    params.listField = params.listField.substring(0,params.listField.length()-1)
                }
                params.Result = params.listField.trim() + '\n' + LdapName[index].trim()
                membersString = params.Result.replace('\n',',') 
                //membersString = params.listField.replace('\n',',') + LdapName[index] 
            } else{
                params.Result = LdapName[index].trim()
                membersString = LdapName[index]
            }
        }
        for (int i = 0; i < result.size(); i++) {
            if(i == 0){
                members = result[i].trim()

            }
            else {
                members = members + '\n' +result[i].trim()
            }
        }
        params.Members = members
    } else {
        flash.message = params.inputField + " not found in LDAP. Please contact TECH CUST CARE"
        params.Result = params.listField.trim()
        membersString= params.listField.replace('\n',',')
        //println "Not Found"
    }  
    membersString = membersString.replace('\r','')
    MGExecutingGroupInstance.members = membersString.trim()
    render(members)
    render(view:'create')
}
4

1 回答 1

0

Jeka,你不能这样表达两个想法

render(members)
render(view:'create')

我看到你可以这样做的更好方法是这样的:

在您的控制器中,您可以将数据呈现为 JSON:

def addEG_Create () {
    ...
    ...
    render([members:members, openWin:'create'] as JSON)
}

在您的 .gsp 中,您应该这样做:

function callEgCreate(){
      $.ajax({
      type: "GET",
      url: "${createLink(controller: 'MGExecutingGroup', action: 'addEG_Create')}",
      data: {
                "inputField="+$("[name='inputField']").val()
                "listField="+$("[name='listField']").val()
      },
      dataType: 'json',   
      success(function(data) {
            window.open(data['openWin']);
            $('.modal-body').html(data['members']);
            $('#myModal').modal('show');
        });
    }

我没有测试过这段代码,也许它可能有一些错误,但逻辑是这样的。

更新

function callEgCreate() {
    $.ajax({
        type: "GET",
        url: "testeChamada",
        data: {"inputField": $("[name='inputField']").val(), "listField" : $("[name='listField']").val()},

        dataType: 'json',
        success: function (data) {
            window.open(data['openWin']);
            $('.modal-body').html(data['members']);
            console.log(data['members']);
        }
    });
}

Ps1:在您的控制器中,当您说渲染时,render([members:members, openWin:'create'] as JSON)您必须使用地图键接收页面中的数据[key:value]

Ps2:在你data:身上你犯了一个错误。它应该是带有 Key:Value 的地图

于 2013-08-08T14:57:04.733 回答