gpt4 book ai didi

grails - 从 Controller 传递我的 “own” map 并将其呈现在 View 中

转载 作者:行者123 更新时间:2023-12-02 15:34:08 27 4
gpt4 key购买 nike

所以这是我的 Controller 中的show()方法,其中InsitutionList作为全局变量,但是当我想从list.gsp访问此InsitutionList时,它没有呈现(也没有给出任何错误,例如null值,我认为我正在传递成功)。另外还要在下面提及gsp代码段。

def show(Long id){
def tacticalIndustryCodeInstance = TacticalIndustryCode.get(id);
def query = Institution.where { idParam ->
idInstitution == idParam
}
def institution = query.find(id)
if(!institution){
flash.message = message(code: 'default.not.found.message', args: [message(code: 'institution.label', default: 'Institution'), id])
redirect(action: "list")
return
}

institutionList.putAt(institution.getLongName(), tacticalIndustryCodeInstance)

if(!tacticalIndustryCodeInstance){
flash.message = message(code: 'default.not.found.message', args: [message(code: 'tacticalIndustryCode.label', default: 'TacticalIndustryCode'), id])
redirect(action: "list")
return
}
[tacticalIndustryCodeInstance: tacticalIndustryCodeInstance, institutionList: institutionList]

}

尝试了不同的事情,没有运气:

1)

                    <td><g:link action="show" id="${tacticalIndustryCodeInstance.id}">${fieldValue(bean: tacticalIndustryCodeInstance, field: "id")}</g:link></td>

<td>${fieldValue(bean: tacticalIndustryCodeInstance, field: "industrySector")}</td>

<td>${Institution.executeQuery("Select longName from Institution where idInstitution = :id?",[id : $(fieldValue(bean: tacticalIndustryCodeInstance, field: "id"))])}</td>
</tr>
</g:each>

2)像这样更简单也无法正常工作
            <g:each in="${institutionList}" var="institutionListInstance">
<td>${fieldValue(bean: institutionList, field: "longName")}</td>
</g:each>

3)
<table id="tacticalIndustryCodeTable" class="center">
<thead>
<tr>
<g:sortableColumn property="id" title="${message(code: 'tacticalIndustryCode.id.label', default: 'Institution Id')}" />

<g:sortableColumn property="industrySector" title="${message(code: 'tacticalIndustryCode.industrySector.label', default: 'industrySector')}" />

<g:sortableColumn property="longName" title="${message(code: 'institution.longName.label', default: 'longName')}" />

</tr>
</thead>
<tbody>
<g:each in="${institutionList}" var="institutionListInstance">
<td>${institutionListInstance.key}</td>
<g:each in="${institutionListInstance.value}" var="item">
<td>${item.id}</td>
<td>${item.industrysector}</td>
</g:each>
</tbody>
</table>

最佳答案

看来您正在更改错误的 Action 或gsp。一旦您没有在“显示”操作中指定 View ,Grails就会渲染show.gsp,但是您希望在list.gsp上显示“institutionList”。

关于grails - 从 Controller 传递我的 “own” map 并将其呈现在 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14348406/

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