我的html中有一些重复的选择标签,因此我想在 Play 中创建一个自定义选择标签,它将选择的名称属性(这可以很容易地完成)和一个列表对象作为参数,通过它我创建选项动态标记。
基本上我想做这样的事情
////// custom tag stored in FormSelect.html///////
<select name="${_selectName}">
#{list ${_options}, as: 't'}
<option value="${t.Description}"> ${t.Description} </option>
#{/list}
</select>
///////calling the custom tag from another html file//////////
Type:
#{FormSelect selectName:'typ', options:types /}
Region:
#{FormSelect selectName:'reg', options:regions /}
types和regions变量是Vector并且从 Controller 转发。我希望选择标记处的 ${_options} (在 #{list} 内)获取 types 和 regions 的值强>
当我执行上面的代码时,我得到这个异常
Template execution error
Execution error occured in template /app/views/tags/FormSelect.html. Exception raised was MissingMethodException : No signature of method: Template_1002.$() is applicable for argument types: (Template_1002$_run_closure1_closure2) values: [Template_1002$_run_closure1_closure2@127a1d8] Possible solutions: _(java.lang.String), is(java.lang.Object), run(), run(), any(), get(java.lang.String).
In /app/views/tags/FormSelect.html (around line 2)
1: <select name="${_selectName}">
2: #{list ${_options}, as: 't'}
3: <option value="${t.Description}"> ${t.Description} </option>
4: #{/list}
5: </select>
提前致谢
最佳答案
而不是
#{list ${_options}, as: 't'}
<option value="${t.Description}"> ${t.Description} </option>
#{/list}
用途:
#{list items:_options, as: 't'}
<option value="${t.Description}"> ${t.Description} </option>
#{/list}
这应该可以解决您当前的错误。
关于java - playframework - 在自定义选择标签中设置列表参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7282599/