Hi,
I am searching in documentation but i can't find an example with a dataKey in a dropdown list. My objects have a different key from your default name 'value' so i am trying to use dataKey in order to use this custom key name.
I need something like this but it doesn't work:
<p-dropdown (onChange)="doSomething($event)" dataKey="{{ifTrue ? 'key1' : 'key2}}" [options]="arrayObj">
<ng-template let-option pTemplate="item">
<div>
<div>{{option.label ? option.label : option}}</div>
</div>
</ng-template>
</p-dropdown>
dataKey is used for faster equality checks, we can add it but not sure that would help your case which is not clear to me.
Seems it already has it.
I'm commenting here but maybe I need a separate issue?
In fact, I wanted a dropdown that does not select the option Object as value but the dataKey as value.
So instead of having {code:'UK', label: 'United Kingdom'} as value I'd want 'UK' (with dataKey="code").
Would this be possible?
@beaumkr I have the same problem with you.
I have array and objects inside of it like this,
[
{
name: 'Recep',
username: 'recepcan'
}
]
I want to display 'name' key with optionLabel
I want to set model username key with dataKey, is this possible?
Most helpful comment
I'm commenting here but maybe I need a separate issue?
In fact, I wanted a dropdown that does not select the option Object as value but the dataKey as value.
So instead of having {code:'UK', label: 'United Kingdom'} as value I'd want 'UK' (with dataKey="code").
Would this be possible?