Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
Get all attributes from model

I try to list all attibutes from a model class define in my angular app.

Here is an example of my model.

export class BiduleList {
  config: {
    attribute01: string;
    attribute02: number;
  }
  configuration: {
    trululu: {
      attribute03: string;
      attribute04: number;
      attribute05: number;
      attribute06: number;
    }
  }
}

I need to loop over all the attributes to build a form to define the associated data.

So I need to keep the layout, i.e. have the information that attribute03 is contained in trululu itself contained in configuration

Here is an example of what I want to build from this information :

public configurationTrululu: { [key: string]: QuestionBase<any> };

this.configurationTrululu = {
  attribute03: new InputQuestion({
    questionContainerClass: FORM_FIELD_COL_FULL,
    textLabel: "attribute03",
  }),
  attribute04: new InputNumberQuestion({
    questionContainerClass: FORM_FIELD_COL_FULL,
    textLabel: "attribute03",
  }),
  attribute05: new InputNumberQuestion({
    questionContainerClass: FORM_FIELD_COL_FULL,
    textLabel: "attribute03",
  }),
  ...
}

If possible I would like to avoid having to define all attributes in a constructor like this:

constructor() {
  this.config = {
    attribute01 = '',
    attribute01 = 0
  };
}

PS: After a question in comment

when I define a new BiduleList(); like that :

public biduleList: BiduleList = new BiduleList();

biduleList is empty and I can't extract all attribute from him. When I display the result of Object.entries in console :

console.log('biduleList', this.biduleList);
>>> biduleList > BiduleList

console.log('entries', Object.entries(this.biduleList));
>>> entries >Array(0)

PSS: I know that in PHP for example you can use the get_class_vars or get_object_vars function

Here an example : https://onlinephp.io/c/d419d

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need create an object with values. As you're working with classes you can

export class Fool{
  name:string;
  group:{
    op1:number;
    op2:number;
  }
  schema(){
    const fool=new Fool();
    fool.name='';
    fool.group={op1:2,op2:3}
    return Object.keys(fool)
  }

And use

schema=new Fool().schema();

You can also in constructor of your class create an object with default values

  constructor(){
    this.name='';
    this.group={op1:2,op2:3}
  }

And create an object and iterate over the Object.keys

 fool=new Fool();
 schema=keys(this.fool)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda