'How can I upload the data to my p-multiSelect?
I'm working with the primeNG component, but I can't load the data.
this.listadoProductos = this.resolucionDatosCargados['listProduct'];
this.parametros['producto'] = this.listadoProductos;
console.log(this.parametros['producto']);
<!--MultiSelect-->
<h4>Grupo de producto</h4>
<div class="ui-fluid">
<p-multiSelect [options]="listadoProductos" [(ngModel)]="parametros.producto" optionLabel="descripcion" defaultLabel="Producto" display="chip"></p-multiSelect>
</div>
This is the JSON object that it returns to me in the console.
[ [ 1, "Trigo " ], [ 2, "Maíz " ], [ 3, "Arroz " ], [ 4, "Otros granos " ], [ 5, "Aceites " ], [ 6, "Azúcar " ] ]
Solution 1:[1]
I see that you set description
as optionLabel
, but the data don't have this key.
Options
should be an array of object. If the request give you this data, I recommend you to create an array of SelectItem
objects.
var arrayProductos: SelectItem[] = [];
this.listadoProductos.forEach(productos => {
arrayProductos.push({
{label: productos[1], value: productos[1]}
})
})
<p-multiSelect [options]="arrayProductos" [(ngModel)]="parametros.producto" defaultLabel="Producto" display="chip"></p-multiSelect>
Maybe, this may be the error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alba |