我试图在一个类的每个对象上调用一个闭包,然后显示闭包返回的对象。关闭是:
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”。可能有什么问题?