0

我试图在一个类的每个对象上调用一个闭包,然后显示闭包返回的对象。关闭是:

    def activitiesPlanned={
        cal.set(this.plannedStartDate)
        def planDateMonth=cal.get(Calendar.MONTH)
        def planDateYear=cal.get(Calendar.YEAR)
    }

我打的电话是:

 def getActivitiesPlanned(int month,int year){
       countActivitiesPlanned=ProgressData.each{it.activitiesPlanned.findAllWhere(planDateMonth:month,planDateYear:year).count()}
    println countActivitiesPlanned
}

域类 //EDIT

package main
class ProgressData {
//String milestoneName
String taskId   //Added later
String taskDescription
String taskCategory
Integer plannedHours  
Integer actualHours      
Date plannedStartDate     
Date actualStartDate     
Date plannedEndDate     
Date actualEndDate     
Integer stepsCreated=0    
Integer stepsExecuted=0   
String status   //Originally Completed
String assignedTo
//String unplanned
String accepted //Added later
def ProgressData(){}

static constraints = {
   //milestoneName(blank:false)
   taskDescription(blank:false)
   taskCategory(blank:false)
   plannedHours(blank:false)
   actualHours(blank:false)
   id generator:"assigned",name:"taskId"
}

 Calendar cal=Calendar.getInstance()
 def activitiesPlanned={
        cal.set(this.plannedStartDate)
        def planDateMonth=cal.get(Calendar.MONTH)
        def planDateYear=cal.get(Calendar.YEAR)
    }
static hasMany=[defects:DefectData]

}

我得到:“没有这样的属性:activityPlanned for class:main.ProgressData 可能的解决方案:activityPlanned”。可能有什么问题?

4

1 回答 1

0

我认为你不想要 .each{} 而不是 .sum{}

例子:

def listThing = [1,2,3]
def sumOfList = listThing.sum{it}
assert sumOfList == 6

ProgressData 也是一个域类,所以你不能.each{}在它上面使用。你必须这样做ProgressData.list().each{,我的意思ProgressData.list().sum{是我认为你正在尝试做的事情。

此外,activityPlanned 关闭不会返回任何活动......

于 2012-06-22T18:54:55.580 回答