我想在grails中创建一个选择框。我使用的是2.1.0。我有一个视图页面,显示一个名为class的选择框。但它没有显示出任何价值。当我将它渲染为json时,我在select的from属性中使用的列表工作正常。任何人都可以让我的组合框为我工作吗?以下是我的代码:
我的观看页面>>>
<g:form controller="admistratorAction" action="addStudent">
<table class="centerTable">
<div class="height"></div>
<tr>
<td><label>Full Name :</label></td>
<td><g:textField name="fullname" id="fullname" class="field"/></td>
</tr>
<tr>
<td> <label>Admission Class :</label></td>
<td><g:select name="class" id="class" class="field" from="${classList}" noSelection="['':'-Choose a class-']"/></td>
</tr>
<td colspan="2" align="right"><g:submitButton name="createSubmit" value="Create" class="button" onclick="return confirm('Are you sure???')"/></td>
</tr>
</table>
</g:form>
这是我的控制器&gt;&gt;
package administrator
import common.classes.Classes
import grails.converters.JSON
class AdmistratorActionController {
def addStudent = {
render "add student"
}
def classList = {
def classes = Classes.executeQuery("SELECT c.classes FROM Classes c")
def all_class = [classes : classes]
render all_class as JSON
}
}
答案 0 :(得分:1)
您无需将其转换为JSON即可将其存储在gsp页面
中class AdmistratorActionController {
def addStudent = {
def n = params.fullName
def c = params.class
// do something with them
}
def classList = {
def classes = Classes.list()
// pass details to view 'classList'
[classList : classes]
}
}
创建 - &gt;视图/ administratorAction / classList.gsp 你准备好了吗?你可以在其中获得$ {classList}