Use complex object as value field

Hi,

I have a scenario, where I load and write a JSON file to a database. The content of that JSON contains the whole object as JSON. In my situation I want to have a DropDownList that reads a list of items T from the database. The previously loaded JSON contains a property of type T. This property is settable through the DropDownList. If I select a value from the DropDownList I want to store the complete object to the object and therefore as JSON to the database.

Database obj

{
  ...
  "propOfTypeT": { "id": 1, "name": "name1" },
  ...
}


Data Source for DropDownlist:

[
  {"id": 1, "name": "name1" },
  {"id": 2, "name": "name2" }
  {"id": 3, "name": "name3" }
]

if I select the second entry I want the resulting json to be:

{
  ...
  "propOfTypeT":  { "id": 2, "name": "name2" }
  ...
}

How do I achieve this. My current solution was to listen on (valueChange) and read from getDataFromValue. Is there some workaround or a solution on your side that solved this issue?

MaterialDesign solves it like this way:

<mat-select [(ngModel)]="item.propOfTypeT" [compareWith]="compareWithFunction">
<mat-option *ngFor="let item of items | async" [value]="item">
{{item.name}}
</mat-option>
</mat-select>




Possibly related to Object as Value Field | Angular Forums | Syncfusion

1 Reply

PM Ponmani Murugaiyan Syncfusion Team December 10, 2020 04:52 PM UTC

Hi Michael, 

Thanks for contacting Syncfusion support. 

Query1: if I select the second entry I want the resulting json to be: 
 
You can get the selected item as per your requirement using select event itemData as like below screenshot. 

public onSelect(args) { 
    console.log(args.itemData); 
  } 
 
 
Also, we would like to inform you that, currently the value property accepts only String, Number or Boolean value. So, we are considering this (“Bind the dropdownlist value property as object”) as a feature in our end. This support will be included in any one of our upcoming releases. You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through the below link.  
   

Regards, 
Ponmani M 


Loader.
Up arrow icon