我正在尝试将类别和子类别添加到组织(当前登录用户)。我可以添加类别但未能将子类别添加到组织。当我尝试时,收到以下消息:
No signature of method: com.vproc.market.Follower.addToSubCategories() is applicable for argument types: (com.vproc.market.SubCategory) values: [com.vproc.market.SubCategory : 4].
我尝试按照以下组织控制器的方法将类别和子类别添加到组织。
组织控制器.groovy
def follow() {
Subscriber loggedinSubscriber = subscriberService.getLoggedinSubscriber()
Party organization = loggedinSubscriber?.customer?.party
def marketInstance = Category.get(params.abc)
def follower = new Follower()
follower.followedBy = organization
follower.category = marketInstance
def sub = params.list('subcategories')
sub.each { id ->
follower.addToSubCategories(SubCategory.get(id))
}
follower.save(failOnError: true);
flash.msg = "Okay. This market is now on your watchlist."
redirect (action: "profile")
}
在这种方法中,我在以下行中收到错误:
follower.addToSubCategories(SubCategory.get(id))
问题标题中提到了这一点。
组织.groovy
package com.vproc.member
import java.util.Date;
import com.vproc.market.SubCategory;
class Organization extends Party{
String orgName
Person contact
String orgSize
boolean isVendor = false
static hasMany = [follows: SubCategory]
static constraints = {
orgName blank: false
orgSize blank: false
}
}
追随者.groovy
package com.vproc.market
import com.vproc.member.Organization;
class Follower {
Category category
Organization followedBy
SubCategory subCategory
static constraints = {
}
}
关注者是将类别和子类别添加到组织并存储的域。
类别.groovy
package com.vproc.market
import com.vproc.enquiry.Enquiry;
class Category {
String name
String description
static constraints = {
}
static hasMany = [ subCategories: SubCategory ]
}
子类别.groovy
package com.vproc.market
import com.vproc.enquiry.Enquiry;
class SubCategory {
String name
static hasMany = [requirements: Enquiry]
static belongsTo = [ category: Category]
static constraints = {
requirements nullable:true
}
}
gsp 文件
<g:form controller="organization" params="[temp : marketInstance?.id]" action="follow" method="post">
<g:hiddenField name= "abc" value="${marketInstance?.id}" />
<g:hiddenField name="id" value="${subcategory?.id}" />
<div style="margin-left:200px">
<input type="button" class="button-inner" id="check1" value="Check All" />
<input type="hidden" id="isChkd" value="true" />
<g:each var="subcategory" in="${subCategroyInstanceList}">
<div>
<g:checkBox class="cb1-element" name="subcategories" value="${subcategory.id}"/>
<label for="subcategories"> ${subcategory.name}</label>
</div>
</g:each>
<button class="btn btn-inverse">Submit</button>
</div>
</g:form>
摘要:我想向组织添加类别和子类别。我可以成功添加类别,但未能将子类别添加到组织。
以下行中出现错误:
def sub = params.list('subcategories')
sub.each { id ->
follower.addToSubCategories(SubCategory.get(id))
}
没有方法签名:com.vproc.market.Follower.addToSubCategories() 适用于参数类型: