2011-09-02 40 views
2

我在我的html中有一些重复选择标记,因此我想创建一个自定义选择标记,它将作为参数选择名称属性(可以完成很容易)和一个列表对象,我通过它动态地创建选项标签。playframework - 在自定义选择标记中设置列表参数

基本上我想要做这样的事情

////// 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 /} 

类型地区变量矢量和控制器转发。我想$ {_选项}在选择标签(内#{list}里)当我excecute上面的代码我得到这个例外,拿类型地区

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: [[email protected]] 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> 

THX提前

+0

你有什么问题?你会得到什么错误?你有没有试过这段代码?Vector中的类是什么?他们的代码? –

+0

好的谢谢你的回复,是的,我试过了代码,我得到一些异常,请检查第一篇文章 – hari

回答

2

而不是

#{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} 

这应该解决您的当前错误。

+0

它确实解决了这个异常,但它没有帮助我很多,现在我得到一个空的下拉框,它不遍历列表 – hari

+0

Sory我的代码中有一个错字,所以你的解决方案完美无缺。感谢你的帮助 – hari

相关问题