Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get object data from select ng-options
Message
 
 
À
19/11/2015 04:31:23
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01627613
Message ID:
01627628
Vues:
37
>>Update. Never mind, have an idea of how to solve it.
>>
>>Hi everybody,
>>
>>Part of my directive's template is the following:
>>
>>
>><select class="col-md-3 form-control" ng-model="selectedItemId" id="item" name="item"
>>                ng-disabled="!selectedCategoryId"
>>               
>>                ng-options="c.itemId as c.descrip for c in metaData.items | filter: {departmeId:selectedDepartmentId, categoryId:selectedCategoryId}">
>>            <option value="">@String.Format(Labels.selectX, Labels.item)</option>
>>        </select>
>>
>>Now, the metaData.items array also contains department, category, item columns. I want to somehow get them when I select the item from the list.
>>
>>What should I change here to be able to get to them? I would want to preserve ng-model = "selectedItemId" if possible and perhaps somehow get the info using ngChange event?
>>
>>Thanks in advance.
>
>You could get the object from the selectedItemId. (using jQuery):
var item = $.grep(metadata.items, function(e){ return e.id === selectedItemId; })[0];
But why can you not have the item itself in ng-model ?

Yes, I've changed my mind and decided to use item itself as ng-model and get other properties using ng-change.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform