0

我正在尝试将类别和子类别添加到组织(当前登录用户)。我可以添加类别但未能将子类别添加到组织。当我尝试时,收到以下消息:

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() 适用于参数类型:

4

2 回答 2

2

Just a quick look at your domains, the Follower domain has direct association with SubCategory. You can simply assign subCategoty to that no need for follower.addToSubCategories(SubCategory.get(id))

Could be something like this:

follower.subCategory = SubCategory.get(id)
于 2013-11-05T14:09:50.590 回答
0

我目前正在研究 Grails,也发现了类似的问题。我正在使用 Grails 2.3.7,我发现了这个https://github.com/grails/grails-datastore-test-support/issues/1

即使从这个链接它提到这是一个错误,但我仍然不确定。到目前为止,我只是执行以下操作,它对我有用:

if(follower.subCategories == null){
    follower.subCategories = [] 
}
def sub = params.list('subcategories')
  sub.each { id ->
  follower.subCategories.add(SubCategory.get(id))
}

如果您对此问题有更好的解决方案,请告诉我。我也很想知道。

于 2015-03-16T08:50:57.467 回答