我想将params.sort传递给我的控制器。如果我改变我的普惠制下Grails将点传递给控制器
<tr>
<g:sortableColumn property="sku" title="SKU" />
<g:sortableColumn property="description" title="Description" />
</tr>
现在:
<tr>
<g:sortableColumn property="material.sku" title="SKU" />
<g:sortableColumn property="material.description" title="Description" />
</tr>
和我的控制器部分:
if (params.sort && params.order == "asc") {
pricesInPriceList = row.prices.sort{it."${params.sort}"}
}
if (params.sort && params.order == "desc"){
pricesInPriceList = row.prices.sort{it."${params.sort}"}.reverse()
}
if (params.sort && params.order == "asc") {
pricesInPriceList = row.prices.sort{it.material."${params.sort}"}
}
if (params.sort && params.order == "desc"){
pricesInPriceList = row.prices.sort{it.material."${params.sort}"}.reverse()
}
[priceListInstance: row, pricesInPriceList: pricesInPriceList]
它正常工作与以下GSP为什么发生这种情况?现在我的params.sort有一个值material.sku例如但如果我想评估it."${params.sort}"
它不起作用。但是,如果我将我的params.sort更改为sku,然后将我的控制器更改为it.material."${params.sort}"
,所有内容都可以正常工作。我在哪里犯错? 谢谢。
是什么'it' ,你在哪里得到它,它包含什么? –
看看http://stackoverflow.com/questions/7784276/grails-accessing-nested-fields-using-gstrings或http://stackoverflow.com/questions/4077168/access-object-properties-in-groovy -using –
@beccagaspard谢谢。这就指出了问题的核心。但是我仍然需要注入我的材质实例(通过在控制器中声明它并没有太大区别)。我有一个列parent.child.property和第二个属性查看。最优雅的解决方案将是有params.sort,无论这是parent.child或父属性,并使用相同的代码。 – Robert