I saw the following example of getting record :
import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
const FIELDS = [
'Contact.Name',
'Contact.Title',
'Contact.Phone',
'Contact.Email',
];
export default class WireGetRecordDynamicContact extends LightningElement {
@api recordId;
@wire(getRecord, { recordId: '$recordId', fields: FIELDS })
contact;
get name() {
return this.contact.data.fields.Name.value;
}
}
I want to fetch a record the same, but i receive a list of fields from the design component, for example "Phone,Industry", so i don't have it defined like in this example.
The problem is i am formatting the fields in connectedCallback()
import { LightningElement, track, api } from 'lwc';
export default class RecordProgressBar extends LightningElement {
@track progress = 0;
@api fields;
fieldsFormatted = [];
connectedCallback() { // initialize component
var i;
var fieldsSplit = this.fields.split(';');
console.log(this.fieldsFormatted);
for(i = 0; i < fieldsSplit.length; i++) {
console.log('a' + fieldsSplit[i] + 'a');
console.log(fieldsSplit[i].length);
if(fieldsSplit[i].length > 0 ) {
this.fieldsFormatted.push('Account.' + this.fieldsSplit[i]);
}
}
console.log(this.fieldsFormatted);
}
}
So how can i use @wire with fieldsFormatted, if this var is field only after init?
{ "Field1": "value1", "Field2":"value2"}
?