2013-10-04 2 views
0

gsp를 만들고 편집 할 때 렌더링되는 _form.gsp에 동적 드롭 다운이 있습니다. 그것은 잘 작동하지만, 선택한 값을 edit.gsp에 표시하고 싶습니다.Grails 동적 드롭 다운에서 edit.gsp에 대해 선택된 값 추가

다음 예에서

<g:select name="plant.id" id="plant" from="${MCM.MGPlant.list(sort:'member')}" value="${MGMatriceInstance?.plant?.id}" optionKey="id" noSelection="${[null: 'Select One...']}" 
      onchange='loadCostCenter(this.value);'/> 
    <g:select id="costCenter" name="costCenter.id" from="${[]}" optionKey="id" noSelection="${[null: 'Select One...']}"/> 


<script type="text/javascript">   
     function loadCostCenter(init) 
      { 
       var root="${resource()}"; 
       var plantid = document.getElementById('plant').value; 
       var url = root+'/MGMatrices/findCostCenterForPlant?plantId='+plantid; 

       jQuery('#costCenter').load(url); 
      }   
</script> 
+0

시도 선택, 사용 가치 속성 – Visme

+0

나는 그것을 추가하고 그것을 작동합니다. 또한 두 번째 드롭 다운에서 선택한 값을 표시 할 수도 있습니다. 그러나 그것은 거기에서 작동하지 않았다. – Jerika

+0

내 대답 필드에 업데이트 된 코드가 표시됩니다. – Visme

답변

0

_form.gsp은 선택에서 국가를 클릭하면, 그것은 아약스 국가의 locaions를 표시합니다. 장소 대신 국가 및 비용 장소에 공장을 교체하십시오.

_temp1 템플릿에는 plant 및 div (비용 드롭 다운의 경우)와 텍스트 상자 (편집의 비용 ID 저장의 경우) 만 넣습니다.

다른 템플릿을 비용으로 생성하십시오. 플랜트가 동적으로 선택되면 비용이 표시됩니다.

편집 작업에서 보려면 plantInstance 및 costInstance를 보내야합니다.

create.gsp 및 edit.gsp에서

_form.gsp에

........... 
<script type="text/javascript"> 
    jQuery(function() { 
     getSelectedCountry(); 
    }); 

    function getSelectedCountry(){ 
     var selectedCountry = jQuery("#country").val(); 
     var locationId = jQuery("#locationId").val(); 
     alert(locationId) 
     if(selectedCountry != ''){ 
      if(locationId!=''){ 
       ${remoteFunction (controller: 'country', action: 'locations', params: '\'countryId=\' + selectedCountry+\'&locationId=\'+locationId', update: 'updateLocation')} 

      } 

      else 
      ${remoteFunction (controller: 'country', action: 'locations', params: '\'countryId=\' + selectedCountry', update: 'updateLocation')} 
     } 
    } 
</script> 

...... 
      <g:render template="form" /> 
...... 

:

_locations.gsp 컨트롤러 행동

<g:select id="location" name="location" from="${locations}" value="${locationInstance.id}"optionKey="id" noSelection="${[null: 'Select One...']}"/> 

<g:select name="country" id="country" from="${com.ard.Country.list()}" 
optionKey="id" noSelection="${['': 'Select']}" value="${countryInstance?.id}" 
      onchange='getSelectedCountry();'/> 

<div id="updateLocation"></div> 

<g:textField name="locationId" value="${locationInstance.id}"/> 

,

def locations(){ 
      def country = Country.get(params.countryId) 
      def locations = country.locations 
        def loc 
        if(params.locationId) 
       loc = Location.get(params.locationId) 
      render(template:"locations",model[locations:locations,locationInstance:loc]) 
    } 
편집 작업에

: 공장

edit(){ 

...... 

render(view:"edit" ,model:[countryInstance:country,locationInstance:locationInstance] 

} 
+0

작동하지 않았습니다. jQuery 함수가 호출되지 않습니다. 내 코드에 대한 해결 방법이 있습니까? – Jerika

+0

작성 및 편집 페이지에 jquery를 포함시켜야합니다. – Visme

+0

예. 비용 ID에 대한 텍스트 상자를 추가 할 필요가 없습니다. – Jerika

관련 문제