2011-08-05 121 views
1

我正在嘗試使用教程here實現鏈接下拉框。雖然我的教程並不像教程中那麼簡單。Grails鏈接下拉

我想鏈接Load類中的create.gsp視圖的下拉框。每個負荷屬於Account類中的一個帳戶,每個帳戶屬於User類中的一個用戶,並且每個用戶都有幾個類別爲Address的貨物目的地。

我的目標是根據選擇哪個帳戶來確定貨物目的地的更新日期。

我無法理解教程中的AJAX函數(步驟3),以及它如何與Grails函數(步驟4)相關。

這裏是AJAX代碼:

 function respondToSelect(event) 
{ 
     new Ajax.Updater("memberSelect", 
      "/chainedSelect/family/updateSelect", 
      {method:'get', parameters: {selectedValue : $F("familySelect")} } 
     ); 
} 

這裏是Grails的方法:

def updateSelect = { 

    def familySelected = Family.find("from Family as family where family.surname=:surname", [surname:params.selectedValue]) 

render (template:"selectMember", model : ['familySelected' : familySelected]) 

} 

如果有人可以只解釋一下什麼是AJAX功能的第三個參數是做我認爲我可以計算Grails脫穎而出。

{method:'get', parameters: {selectedValue : $F("account")}}

+0

[後續問題在這裏](http://stackoverflow.com/questions/6984989/grails-select-will-not-return-correct-data)。 –

回答

4

如果有人可以只解釋一下什麼是AJAX 函數的第三個參數是做

第三個參數是參數的對象,獲得通過的更新,告訴它如何將HTTP請求發送到服務器。

使請求的HTTP GET請求:

method:'get' 

將以下命名查詢參數:

{selectedValue: $F("account")} 

$F是一個原型捷徑retrieve the value of an element。在這種情況下,它將獲取ID爲account的DOM元素的選定值。

這最終導致類似如下的要求:

GET /chainedSelect/family/updateSelect?selectedValue=someValue 

其中「someValue中」是在「賬戶」的當前選擇的項目選擇列表。