如何使用列表中的值在
我试图在闪存中传递新对象,但是我不知道如何获取用于生成g:select数据的列表中的索引。
最佳答案
假设您将Book对象存储在 Controller 级别的flash.book中,则第二页如下所示:
<html>
<head>
<g:javascript library="prototype" />
<g:javascript>
function showLast(selectedId) {
if (selectedId) {
$$('#books option[value=' + selectedId + "]")[0].selected = true;
} else {
$('books').selectedIndex = 0;
}
};
Event.observe(window, 'load', init, false);
function init() {
showLast(${flash?.book?.id});
}
</g:javascript>
</head>
<body>
<g:select id="books" name="id"
from="${Book.list()}"
value="title"
optionValue="title"
optionKey="id"
/>
</body>
</html>
关于list - Grails g:选择设置selectedIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2196707/