2013-02-23 83 views
0

我在嘗試更新組合框的內容(使用Griffon 1.2.0和JavaFX插件)。正在更新Griffon JavaFX組合框

我的模型:

class MyModel { 
    List monthList = FXCollections.observableList([new DateMidnight()]) 

    def convertDate = [ 
      fromString: { String s -> 
       return new DateMidnight(DateTimeFormat.forPattern("yyyy-MM").parseDateTime(s)) 
      }, 
      toString: { DateMidnight d -> 
       return "2011-10" 
      } 
    ] as StringConverter 
} 

我的觀點包括:

comboBox(items: (model.monthList), converter: model.convertDate) 

現在我有一個被調用的控制器操作,當他們按一個按鈕:

def load = { 
     execInsideUIAsync { 
      def months = myService.buildMonthList() 
      model.monthList.addAll(months) 
     } 
} 

的問題是組合框內容永不改變。任何人都可以幫助我瞭解我錯過了什麼嗎?

有組合框上沒有文檔尚未http://groovyfx.org/docs/guide/single.html#choiceBoxComboBox

而且,我已經正確實施了轉換?

回答

0

問題是,GroovyFX.comboBox創建一個新的列表,而不是使用您傳遞的參數作爲項目:此問題也出現在tableView中。臨時解決方法是直接設置items屬性,像這樣

comboBox(id: 'combo') 
noparent { combo.items = model.monthList } 
+0

不幸的是,這並不適用於我。我定義我的組合框: 組合框(ID:「月」,轉換器:model.convertDate) ,然後用noparent塊: noparent { months.items = model.monthList ,然後在我的控制器我更新模型 model.monthList.clear() model.monthList.addAll(months) 但該視圖永不改變。 我一直能夠操縱組合框的唯一方法是直接訪問view.months.items並直接清除/填充它。不理想。 – prule 2013-02-23 22:06:42

+0

嗯,它可能是一個線程問題?我用Griffon 1.2.0和groovyfx/javafx 0.8運行代碼。有關詳細信息,請參閱https://gist.github.com/aalmiray/5023272。該指南詳細介紹了@線程http://griffon.codehaus.org/guide/latest/guide/threading.html#annotationBasedThreading – aalmiray 2013-02-24 09:56:40

+0

嘿,我創建了一個新的應用程序來嘗試你的例子,它工作正常。但我仍然無法在我現有的應用程序中使用它。當我有時間時,我會盡量讓它正常工作。謝謝你的幫助。 – prule 2013-02-25 01:12:46