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

146
Visualizações
it says that nation is undefined but i call the function flagUrl after i know it is defined

this is my function to retrieve information of Nationality , turn it into an alpha2code(eg. "US" , "BR") and then get an imgURL based on that alpha2code (works with the countryflagsapi). I know the function is correct.The problem is i call this function on HTML , and it said that it cant find .alpha_2_code because nation is undefined. JS code:

self.flagUrl =  ko.computed(function(){
        //var txt = data;
        // console.log(txt);
        // var nation = this.records[idx].Nationality;
        //var idx = data;
        //var obj = self.records[idx].Nationality;
        var nation = self.Nationality;
        console.log(nation);        
        var alpha2code = countries.filter((country) => country.Nationality === nation)[0].alpha_2_code;

        
        //console.log(c);
        
        var myPath = "https://countryflagsapi.com/png/" + alpha2code;
        
        return myPath;   
           
          
          
    }, self);

HTML code:

<tr class="row">
                <th class="col-md-2">Nationality</th>
                <td class="col-md-10" data-bind="text: Nationality"></td>
                <td><img  src="" alt="" height=25px width=40px data-bind="attr:{src: flagUrl()}" ></img></td>
            </tr>

The HTML is getting the Nationality data right on here , but it doesnt assign it to the viewmodel.

pls help .

about 4 years ago · Juan Pablo Isaza
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