gpt4 book ai didi

grails - 如何访问在 tag? 中生成的 gsp 文件中的单个值

转载 作者:行者123 更新时间:2023-12-02 15:00:47 25 4
gpt4 key购买 nike

我在 gsp 文件中有以下代码,用于编辑现有列表 (patientPts) 的各个值

<g:each var="points" in="${patientPts}">
<b>Term: ${points.term} - <g:if test="${points.type.equals('C')}">Calculus<br>
</g:if> <g:else>Perio<br>
</g:else></b>
<label for="${points.id}01">Class 0/1:</label>
<input type="text" name="class_01" value="${points.class_01}"
id="${points.id}01">
<br>
<label for="${points.id}2">Class 2:&nbsp;&nbsp;&nbsp;</label>
<input type="number" name="class_2" value="${points.class_2}"
id="${points.id}2">
<br>
<label for="${points.id}3">Class 3:&nbsp;&nbsp;&nbsp;</label>
<input type="number" name="class_3" value="${points.class_3}"
id="${points.id}3">
<br>
<label for="${points.id}4">Class 4:&nbsp;&nbsp;&nbsp;</label>
<input type="number" name="class_4" value="${points.class_4}"
id="${points.id}4">
<br>
</g:each>
<br>
<div class="buttons">
<g:link value="Save" action="save"
params="${[patientPts: patientPts]}">Save</g:link>
<g:actionSubmit value="Cancel" action="index" />
</div>

patientPts 是 PatientPoints 对象的列表,具有以下属性
String courseKey; //Stores the course key of the course for the patient points object
String term; // Stores the term of the patient points object
String type; // Stores the type of the patient points object
Double class_01; //Stores the points for the class 0 and class 1
Double class_2; //Stores the points for the class 2
Double class_3; //Stores the points for the class 3
Double class_4; //Stores the points for the class 4

显示这个
Grade Adjustments edit

我的 Controller 中有一个保存操作,我需要能够在其中获取所有这些对象并保存对它们所做的更改(如果有)。我在执行此操作时遇到了麻烦,因为当它们都由标签生成时,我无法弄清楚如何分别引用每个文本字段。谁能帮我吗?

最佳答案

听起来您想在 GSP 中使用数组或列表绑定(bind)语法。您可以将 PatientPts 对象放在命令对象内的 Set 中,例如:

class PatientCommand {
Set<PatientPts> patientPts
}

在您的 GSP 中,您希望使用索引符号进行绑定(bind):
<g:each var="points" in="${commandInstance.patientPts}" status="i">
...
<input type="text" name="patientPts[${i}]class_01" value="${points.class_01}"
id="${points.id}01">

当表单被提交并绑定(bind)到 PatientCommand 时,数据绑定(bind)器将创建单独的 PatientPts 对象并将它们绑定(bind)到 Set 中(自动创建和增长它)。

关于grails - 如何访问在 <g :each> tag? 中生成的 gsp 文件中的单个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23698120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com