Smarty html_options值属性不工作


Smarty html_options value attribute not working

我试图显示一个下拉列表与smarty html_options。它很好地显示了下拉菜单,但输出值为0,1,2,3,4,5。

但是我想要的值是100,150,200,250,300,350。

= = = = = = PHP =========

$choice_set=array("A","B","C","D","E","F");
$choice_values=array(100,150,200,250,300,350);
$choice=250;

= = = = =自作聪明的家伙 =========

<select name="location">
{html_options values=$choice_values options=$choice_set selected=$choice}
</select>

请帮我整理一下。

从他们的文档来看,似乎您忘记了为选择设置大小位。此外,它说options需要是output(这对我来说似乎是一个非常糟糕的名字)。这样的:

<select name="location" size="{$choice_values|@count}">
    {html_options values=$choice_values output=$choice_set selected=$choice}
</select>

更新:基于Gerald在评论中的优秀观点。

如果你定义了一个关联数组而不是单独的数组,你可以使用options模板值。所以这个也可以:

= = = = = = PHP =========

$choices = array(100 => "A, 150 => "B", 200 => "C", 250 => "D", 300 => "E", 350 => "F");
$choice=250;

= = = = =自作聪明的家伙 =========

<select name="location">
    {html_options options=$choices selected=$choice}
</select>

同样,我经常忘记$smarty->assign我的变量,特别是当我在制作原型或更改某些内容时。在这方面,你可能比我聪明,但值得仔细检查。

很抱歉我的疏忽,我已经有一段时间没有使用smarty了