0

我想在我的视图页面中制作链选择框。我有国家选择框和城市选择框。在城市域中,我有国家 ID。现在我想在选择国家时显示特定国家的城市。但我不知道。我正在使用 grails 2.1.0。我已经对此进行了谷歌搜索并尝试了一些代码。但没有结果。我正在提供我的域、控制器和视图。如何使事件发生变化,使用 country_id 创建城市列表并将其显示在城市选择框中?任何人都可以请帮我吗?

我的国家域名>>>

    package com

class Country {

     String name
    String abbr
    String language

static hasMany = [cities:City]

    static constraints = {
    }
}

我的城市域名>>>

    package com

class City {

   String name 
   String timezone

static belongsTo = [country:Country]

    static constraints = {
    }
}

我的国家控制员>>>

package com

import com.City
class CountryController {

    def index = { }

}

我的浏览页面>>>

<%@ page import="com.Country; com.City" %>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="layout" content="country" />
</head>
<body>
  <form>
    <g:select
      optionKey="id" optionValue="name" id="countryname" name="countryname"  from="${Country.list()}">
    </g:select>
    <g:select optionKey="id" optionValue="name" id="cityname" name="cityname" from="${City.list()}"></g:select>
  </form>
</body>
</html>
4

1 回答 1

1

尝试进行 Ajax 调用以获取给定国家/地区的城市。

看到这个类似的 SO 问题:Populate dropdown list using ajax In grails

于 2013-05-22T11:17:17.060 回答