View Griffon视图-我可以绑定到数组元素吗

View Griffon视图-我可以绑定到数组元素吗,view,binding,griffon,View,Binding,Griffon,在我的一个模型中 @Bindable contentList = ['A','B','C','D','E','F','G','H','J','K','L','M'] 在我看来 def offset = 0 2.times { outer -> 6.times { inner -> panel(background: Color.white, border: BorderFactory.createLineBorder(Color.black),

在我的一个模型中

@Bindable contentList = ['A','B','C','D','E','F','G','H','J','K','L','M']
在我看来

def offset = 0

2.times { outer ->
  6.times { inner ->
     panel(background: Color.white,
           border: BorderFactory.createLineBorder(Color.black),
           constraints: inner.equals(5) ? 'grow,wrap' : 'grow') {
           label(text: bind {model.contentList[offset++]},
                    font: new Font("Sans Serif",
                    Font.PLAIN, 18))
          }
     }
 }
在初始加载时,这可以正常工作,但当我尝试在控制器中更新数组中的元素时 它没有反映在屏幕上。。有没有办法绑定到数组元素


谢谢

为此,您可以使用
可观察列表
。例如,在模型中,可以将
contentList
声明为:

ObservableList contentList = new ObservableList(['A', 'B', 'C', 'D', 'E', 
   'F', 'G', 'H', 'J', 'K', 'L', 'M'])
如果您绑定到
ObservableList
内容
属性,则会在更改时通知您。然后,您可以使用
转换器
根据特定索引检索适当的值,例如:

def offset = 0
def c = { o, v -> v[o] }
2.times { outer ->
   6.times { inner ->
       label(text: bind('content', source: model.contentList, 
                        converter: c.curry(offset++)))
   }
}

作为补充,您能否解释bind语句(“内容”字段从何而来)以及curried闭包的用法?
content
observateList
()的一个有界属性。我使用curry使每个转换器的闭包记住它们当前的
offset
,否则它们将始终使用最新的
offset