使用 smarty 重现 3 个级别的选项组
在最近的一个项目中,我发现他们正在使用 smarty,并且客户需要一个包含 3 个级别的选项组。我从未使用过 smarty,而且我发现这种特殊情况从头开始有点困难。
我需要做下一步,但要和聪明人一起做:
<select>
<optgroup label="Level One"></optgroup>
<optgroup label="Level Two" style="padding-left:15px"></optgroup>
<option style="padding-left:30px"> A.B.1 </option>
<optgroup label="Level Two" style="padding-left:15px"></optgroup>
<option style="padding-left:30px"> A.B.2 </option>
<optgroup label="Level One"></optgroup>
<optgroup label="Level Two" style="padding-left:15px"></optgroup>
<option style="padding-left:30px"> A.B.1 </option>
<optgroup label="Level Two" style="padding-left:15px"></optgroup>
<option style="padding-left:30px"> A.B.2 </option>
</select>
我还想知道通知这个聪明人的最佳方式是什么;具有 3 个级别的数组或如何(我使用 PHP)以及如果我有默认选项我必须如何指示它。
先感谢您!
更新:实际使用的代码
$arr['Sport'] = array(6 => 'Golf', 9 => 'Cricket',7 => 'Swim');
$arr['Rest'] = array(3 => 'Sauna',1 => 'Massage', "Test" => array(10 => 'Other', 11 => 'Option'));
$smarty->assign('lookups', $arr);
$smarty->assign('fav', 7);
实际上只给了我 2 个级别。
更新 2
In a recent project I have found that they're using smarty and the client needs a option group of 3 levels. I've never used smarty and I find this particular case a little hard to do it from scratch.
I need to do the next but with smarty:
<select>
<optgroup label="Level One"></optgroup>
<optgroup label="Level Two" style="padding-left:15px"></optgroup>
<option style="padding-left:30px"> A.B.1 </option>
<optgroup label="Level Two" style="padding-left:15px"></optgroup>
<option style="padding-left:30px"> A.B.2 </option>
<optgroup label="Level One"></optgroup>
<optgroup label="Level Two" style="padding-left:15px"></optgroup>
<option style="padding-left:30px"> A.B.1 </option>
<optgroup label="Level Two" style="padding-left:15px"></optgroup>
<option style="padding-left:30px"> A.B.2 </option>
</select>
I would also want to know what is the best way to inform this smarty; with an array of 3 levels or how (I'm using PHP) and if I have a default option how I've to indicate it.
Thank you in advance!
Update: code actually using
$arr['Sport'] = array(6 => 'Golf', 9 => 'Cricket',7 => 'Swim');
$arr['Rest'] = array(3 => 'Sauna',1 => 'Massage', "Test" => array(10 => 'Other', 11 => 'Option'));
$smarty->assign('lookups', $arr);
$smarty->assign('fav', 7);
This actually is giving me only 2 levels.
Update 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看{html_options}。
编辑
Smarty3 模板
生成以下 HTML(手动缩进),
这看起来非常像人们所期望的。但是在 Firefox 7 中查看此内容,我看到正确嵌套的组显示在同一级别上:
Have a look at {html_options}.
edit
Smarty3 Template
generates the following HTML (manually indented)
Which loooks pretty much like one would expect. But viewing this in Firefox 7, I see the properly nested groups being displayed on the same level: