0

在我的 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}

    }
}

谢谢!!

铁螳螂7x!!

4

1 回答 1

1

答案在于 GPath 表达式。这个做你需要的

model.deviceTypes.devices.flatten().grep{ it.selected }

甚至

model.deviceTypes.devices.flatten().grep{ it.selected == true }
于 2013-02-02T12:09:55.803 回答