0

I have a Select field:

<select
    id="aircraft_id"
    data-id="{{( $obj->exists ) ? $obj->aircraft_id : NULL}}"
    data-placeholder="Wähle ein Flugzeug"
    no-results-text="'Konnte kein Flugzeug finden'"
    class="form-control"
    chosen="directiveOptions"
    name="aircraft_id"
    ng-model="aircraft"
    ng-change="checkSeats(aircraft.id)"
    ng-disabled="newAircraftIdentifier.length > 0 || newAircraftModel.length > 0"
    ng-options="aircraft.ident for aircraft in aircrafts">
</select>

and "aircrafts" json object contains:

[Object { ident="--", id="", seats=""}, 
 Object { id=1, ident="D-3417", seats=2}, 
 Object { id=2, ident="D-1021", seats=2}, 
 Object { id=3, ident="D-4582", seats=1}, 
 Object { id=5, ident="D-FTSD", seats=null}, 
 Object { id=10, ident="D-5970", seats=1}
]

Everything works except that my option in the select is the index of my json Object, and not the id...

so the result is the following:

<option value="0" selected="selected">--</option>
<option value="1">D-3417</option>
<option value="2">D-1021</option>
<option value="3">D-4582</option>
<option value="4" selected="selected">D-FTSD</option>
<option value="5">D-5970</option>

But I want that the option value is my ID in the array like ID 10 in the last item, and not 5... Hope you understand what I mean.

I think the wrong line is this:

ng-options="aircraft.ident for aircraft in aircrafts"

But I dont understand how I fix this.

Thanks in advance,

Leif

goldlife
  • 1,949
  • 3
  • 29
  • 48

2 Answers2

0

Try

aircraft.id as aircraft.ident for aircraft in aircrafts
zian974
  • 71
  • 1
  • 1
  • I try this before, but it isn't work... I found the solution: aircraft.ident for aircraft in aircrafts track by aircraft.id – goldlife Aug 19 '14 at 10:41
0

You shouldn't be concerned with value on option element as it's irrelevant with Angularjs model. DOM created with ng-options will have always values from 0..n, check your $scope.aircraft model for actually selected value

you can also use it as aircraft.id as aircraft.ident for aircraft in aircrafts then the model $scope.aircraft will be updated with only id

maurycy
  • 8,455
  • 1
  • 27
  • 44