Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7934007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:30:31+00:00 2026-06-03T21:30:31+00:00

So I know what the problem is, but I don’t know the proper way

  • 0

So I know what the problem is, but I don’t know the proper way (the syntax) to fix it.

If you take the code from “myFunction” and put it inside the .each loop where I am calling “myFunction” then my code works because “this” is being defined and is within the scope of the JSON object that I am referencing.

But, when I write my function and declare it outside the scope of the JSON object, then it no longer knows what “this” is and returns a value of “undefined”.

How do I pass “this” as an argument to my function so that I can properly grab the values?

    $.getJSON('labOrders.json', function(json) {
    var aceInhibitors = "",
        antianginal = "",
        anticoagulants = "",
        betaBlocker = "",
        diuretic = "",
        mineral = "",
        myFunction = function () {
            aceInhibitors += "<div class='row drugLineItem'>",
            aceInhibitors += "<div class='columns moneydot' style='background:none;'></div>",
            aceInhibitors += "<div class='columns drugTitleWrap'>",
            aceInhibitors += "<div class='row drugTitle'>"+this.name+"</div>",
            aceInhibitors += "<div class='row drugDose'>"+this.strength+"</div>",
            aceInhibitors += "<div class='columns'></div>",
            aceInhibitors += "<div class='columns orderDeets dxRefill'>"+this.refills+"</div>",
            aceInhibitors += "<div class='columns orderDeets dxPillCount'>"+this.pillCount+"</div>",
            aceInhibitors += "<div class='columns orderDeets dxSig'>"+this.sig+"</div>",
            aceInhibitors += "<div class='columns orderDeets dxRoute'>"+this.route+"</div>",
            aceInhibitors += "<div class='columns orderDeets drugTab'>"+this.dose+"</div>"
        }

  $.each(json.medications, function(index, orders) {
    $.each(this.aceInhibitors, function() {
        myFunction();

    });
    $.each(this.antianginal, function() {

    });
  });

  $('#loadMedSections').append(aceInhibitors);



});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:30:32+00:00Added an answer on June 3, 2026 at 9:30 pm

    You have two options:

     $.each(this.aceInhibitors, myFunction);
    

    There’s no need for the wrapper function, and that would have the correct context.

    Second option:

    $.each(this.aceInhibitors, function() {
        myFunction.call(this);
    });
    

    That will call it will the context of the context of the wrapper function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to solve the problem here but I don't know why my code
I have a simple problem but I don't know how to solve it because
I'm facing a problem where I know the root cause but don't see a
I don't know if anyone else even has this problem, or has noticed, but
So, I don't know if the question is explicit enough, but here's my problem:
I know how to save string from EditTexts on android but my problem is:
I know how to fix the problem, but the thing is, my .android directory
I have this problem that I probably understand but don't know how to handle,
It's not a problem but i don't know how to do this; let's say
I'm trying to look up this problem but I don't know what it's called.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.