【发布时间】:2017-03-15 14:48:46
【问题描述】:
我正在尝试使用从数据库中获取的值动态填充 AngularJS 中 <select> HTML 元素的 options。根据文档,我试过这个:
<select
name="student_id"
ng-model="studentData.student_id"
ng-options="student as student.name for student in students track by student.id"
class="form-control">
<option value="">-- choose Agency --</option>
</select>
这很好用。它填充了optionselect HTML 元素,我可以看到填充了学生姓名的下拉值,option 元素的对应值是student_id。
现在的问题是,当我填写所有表单并尝试提交时,它提交了一个 student object 而不是 student_id 作为@987654328 的值@ 元素。
如何提交student_id 而不是学生对象?
【问题讨论】: