2016-11-02 7 views
1

AngularJSの<select> HTML要素のoptionsをデータベースから取得した値で動的に設定しようとしています。ドキュメントによると、私はこれを試しました:Angularjs:動的に値が設定されたオプションselectが値の代わりにオブジェクトを返します

<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でした。

の問題は、今私は、すべてのフォームに必要事項を記入して提出しようとしたとき、それは代わりに学生オブジェクトを提出option select要素の値としてをSTUDENT_IDということです。


は、どのように私の代わりに学生対象student_idを提出するのですか?

答えて

2

コードでは、studentオブジェクト全体を選択します。

ng-options="student.id as student.name for student in students track by student.id" 

注:

ng-options="student as student.name for student in students track by student.id" 

するには、この行を変更し、私はあなたにもtrack byを削除すべきだと思う、私はそれがここには何も持っていないと思います。

関連する問題