簡體   English   中英

Struts2 標簽 單選按鈕

[英]Struts2 Tags Radio button

我有這個遍歷 object 的迭代器。

        <s:iterator value = "choices" status = "key">
        <s:set var = "test" value ="%{#key.index}"/>
             <input type = "radio" name="choices[{key.index}].answer" />
             <s:textfield name = "choices[%{#key.index}].value" value = "%{choices[%{#key.index}].value}"/>
            <br>
        </s:iterator>

其中answer是 boolean 值,我試圖通過單選按鈕設置。

但問題是,在生成的 html 上,單選按鈕。 是這樣的

<input type = "radio" name="choices[%{#key.index}].answer" />

它沒有索引/索引。 它只給了我%{#key.index}

您必須使用屬性標簽來獲取實際值

<input type = "radio" name="<s:property value='%{choices[#key.index].answer}' />" />

更好地使用struts標簽庫的radio標簽,像這樣

<s:radio name="choices[%{#key.index}].answer" / >

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM