Grails 类的每个对象上的闭包
我试图对类的每个对象调用闭包,然后显示闭包返回的对象。 关闭日期为:Grails 类的每个对象上的闭包,grails,closures,Grails,Closures,我试图对类的每个对象调用闭包,然后显示闭包返回的对象。 关闭日期为: def activitiesPlanned={ cal.set(this.plannedStartDate) def planDateMonth=cal.get(Calendar.MONTH) def planDateYear=cal.get(Calendar.YEAR) } 我的电话是: def getActivitiesPlanned(int month,
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
}
域类//编辑
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]
}
我得到:没有这样的属性:activitiesPlanned for class:main.ProgressData可能的解决方案:activitiesPlanned。可能有什么问题?我想你不需要。每个{}而不是.sum{} 例如:
def listThing = [1,2,3]
def sumOfList = listThing.sum{it}
assert sumOfList == 6
另外,ProgressData是一个域类,因此不能使用它上面的.each{}。你必须做ProgressData.list.each{我指的是ProgressData.list.sum{我认为你在做的事情
另外,activitiesPlanned Close不会返回任何活动…Progressdata是您的域类吗?您可以发布完整的代码示例。是的。Progressdata是我的域类。我将发布域类代码