2017-03-28 85 views
0

嗨我在onChange事件中調用remotefunction。我想當用戶從父母下拉列表中選擇,子鼠標下拉屬於父母的ID將顯示,但默認的子塊將被隱藏。我如何在onchange事件中調用兩個函數。調用兩個jQuery函數,onChange

我的代碼:

<g:select optionKey="id" from="${commonList}" class="fullBorderBox" value="${value?."${propertyName}"?."${commonPropertyName}"?.id}" name="${commonPropertyName}.id" noSelection="${['null': message(code: 'common.list.select')]}" onchange="${remoteFunction(
         controller: 'middlewareData', 
         action: 'populateVersion', 
         params: "'typeId=' + this.value + '&&lookUpProperty=' + '${commonPropertyName}'", 
         update: "populateSWVersion${dataindex}" 
        )}; $("#versionBlock${dataindex}").hide();"/> 


<span id="versionBlock${dataindex}"> 
       test="${value?."${propertyName}"?."${commonPropertyName}"?.id}"> 
        <g:select optionKey="id" from="${propertyList}" class="fullBorderBox" name="dummyVal" value="${value?."${propertyName}"?.id}" noSelection="${['null': message(code: 'common.list.select')]}" onclick="populateVersionList(null);" /> 

      </span> 
      %{---pass an dynami id to populate version block pick list----}% 
      <span id="populateSWVersion${dataindex}"></span> 

回答

1

不需要寫在HTML中,所有JS處理。您可以將回調事件移到JS中的函數中。然後做任何你想要的邏輯。

${remoteFunction(
         controller: 'middlewareData', 
         action: 'populateVersion', 
         params: "'typeId=' + this.value + '&&lookUpProperty=' + '${commonPropertyName}'", 
         update: "populateSWVersion${dataindex}" 
        )}; $("#versionBlock${dataindex}").hide(); 

將此代碼移至JS函數。從這個回調中,你可以調用你想要的其他功能。

// make your server call 
    function getData(){ 
    $.ajax({ 
    //.... 
    }); 
    } 

然後簡單絲此功能可將上改變事件,

onchange="getData()"