例如,如果我从数据库中检索以下数据:
--------------------------
| id | name | department|
--------------------------
| 1 | john | HR |
--------------------------
| 2 | peter| accounting|
--------------------------
| 3 | adam | secretary |
--------------------------
我如何创建一个 optgroup 标记以在 optgroup 中显示此结果以具有以下内容:
<select >
<optgroup label='HR'>
<option value='1'>john</option>
</optgroup>
<optgroup label='accounting'>
<option value='2'>peter</option>
</optgroup>
<optgroup label='secretary'>
<option value='3'>adam</option>
</optgroup>
</select>