在我的griffon应用程序中,我可以选中复选框,但是当我点击提交时,我的JOptionPane窗口显示值的空白。关于我可能做错的任何想法?
这是我的型号代码:
=============================================== ===================================
package test1
import groovy.beans.Bindable
class Test1Model {
@Bindable String deviceType
List deviceTypes = [
[title: 'No Devices', selected: true, devices: []],
[title: 'Android Tablets', selected: false,
devices: [
[name: 'Asus Transformer Prime #1', selected: false],
[name: 'Asus Transformer Prime #2', selected: false],
[name: 'Motorola Xoom #1', selected: false],
[name: 'Motorola Xoom #2', selected: false],
[name: 'Sony S Tablet #1', selected: false],
[name: 'Sony S Tablet #2', selected: false]
]
],
[title: 'Android Phones', selected: false,
devices: [
[name: 'Nexus 7 #1', selected: false],
[name: 'Nexus 7 #2', selected: false],
[name: 'HTC Droid Eris', selected: false],
[name: 'HTC EVO 4G LTE', selected: false],
[name: 'Samsung Galaxy Nexus #1', selected: false],
[name: 'Samsung Galaxy Nexus #2', selected: false],
[name: 'Droid Razr Maxx #1', selected: false],
[name: 'Droid Razr Maxx #2', selected: false],
[name: 'Samsung Galaxy S2', selected: false]
]
],
[title: 'iOS Devices', selected: false,
devices: [
[name: 'iPad Gen1', selected: false],
[name: 'iPad Gen2', selected: false],
[name: 'iPad Gen3', selected: false],
[name: 'iPod Touch', selected: false]
]
]
]
}
=============================================== ==========================================
这是我的控制器代码:
package test1
import griffon.transform.Threading
import griffon.util.GriffonNameUtils as GNU
class Test1Controller {
def model
def clear = {
model.griffonClass.propertyNames.each { name ->
model[name] = ''
}
}
@Threading(Threading.Policy.SKIP)
def submit = {
javax.swing.JOptionPane.showMessageDialog(
null, "You have selected: " + model.deviceTypes.devices.grep.{it.selected}
)
println model.deviceTypes.devices.grep.{it.selected = true}
}
}
谢谢!
ironmantis7x !!
答案 0 :(得分:1)
答案在于GPath表达式。这个做你需要的
model.deviceTypes.devices.flatten().grep{ it.selected }
甚至
model.deviceTypes.devices.flatten().grep{ it.selected == true }