samrty 對二維數組資訊不能全部顯示的處理
來源:互聯網
上載者:User
方法一:
{foreach from="$information" item="foo" key="k"}
<tr>
<td>
<input type="radio" name="son_id{$foo.father_id}" id="1" value="1" {if $foo.son_id=="1"}checked="checked"{/if}/>
<label for="son_id">男</label>
<input type="radio" name="son_id{$foo.father_id}" value="2" {if $foo.son_id=="2"} checked="checked" {/if}/>
<label for="son_id">女</label>
<input type="radio" name="son_id{$foo.father_id}" value="3" {if $foo.son_id=="3"} checked="checked" {/if}/>
<label for="son_id">保密</label>
</td>
</tr>
{/foreach}
方法二:
{foreach from="$information" item="foo" key="k"}
<tr>
<td>
{html_radios name=$foo.father_id options=$List checked=$foo.son_id }
</td>
</tr>
{/foreach}
說明:
對於foreach的嵌套迴圈問題,涉及到二維數組的時候,往往總是選中最後一行的資訊(前面的沒有選中,被後面的覆蓋掉了,受到上一級id的牽制),所以name="son_id{$foo.father_id}"中要把上一級的id加上
其中方法二中的$List是數組
$List = array (
"1" => "男",
"2" => "女",
"3" => "保密",
);