Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!