似乎有两种情况下分配给绑定的 groovy 属性 through@Bindable
不会调用侦听器:
(1) 在类本身内分配属性的情况下,例如this.prop = newval
,或者,简单地说,prop = newval
(2) 财产价值不变的情况obj.prop = oldval
有没有解决的办法?理想情况下,它将支持简单的(.)prop=
语法。
代码示例:
import java.beans.*
import groovy.beans.*
int changes = 0
def obj = Binding.newInstance()
obj.propertyChange = { changes++ }
obj.prop = "1st change" // change recorded
obj.twoChanges() // no changes recorded
obj.prop = obj.prop // no change recorded
assert changes == 4 // fails: changes is 1
class Binding {
@Bindable String prop
def twoChanges() {
prop = "2nd change"
this.prop = "3rd change"
}
}