Avatar of skillilea
skillilea asked on

help with array return

Sorry if this is crazy...and thanks in advance for the help.

I have an object that I am trying to keep for my page and use in other methods on the page.  My issues is my Array is not increasing and available when I need it.

//-------OBJ ----//
function IPpage() {

this.Prop1 = "...";
this.FilterAR = [];


//do on create of object
this.LoadFilterList();
}


IPpage.prototype.LoadFilterList = function () {
...
    
    //add the user filters
    $.ajax({
        type: 'POST',
        url: u,
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        data: p,
        error: function (xhr, ajaxOptions, thrownError) {
            ...
            return false;
        },
        success: function (response) {
            var d = response.d;
            if (d) {
                var data = []
                //console.log(d);
                $.each(d, function (indx, val) {
                    data.push({ FGUID: val.FGUID, FilterName: val.FilterName, DefaultView: val.ColView, IsSystem: false }); 
                });
                var t = '', u = '';

[b]               //is this my problem?   is this a reference of the actual property in my main object  [/b]
                o.FilterAR = data.concat(o.StandardFilter());

                //build the system filters
                for (i = 0; i < o.FilterAR.length; i++) {
                    entry = o.FilterAR[i];
                    if (entry.IsSystem) {
                        t += ("<tr data-dguid='" + entry.FGUID + "'><td class='ippFilterHL noSelect jqFilterBtn jqFtitle'>" + entry.FilterName + "</td><td>&nbsp;</td></tr>");
                    } else {
                        u += ("<tr data-dguid='" + entry.FGUID + "'><td class='ippFilterHL noSelect jqFilterBtn'>" + entry.FilterName + "</td><td class='ippSubButton noSelect jqFilterEditBtn jqFtitle'>" + o.lblEdit + "</td></tr>");
                    }
                }
             
            }
        }
    });
};


Is there a better way to load the array?  Basically I have some values that are standard then I hit a table to add more and I want that array to be global for my object.

I want to use it in other methods...

IPpage.prototype.GetFilterObjByFGUID = function () {

    for (var i = 0; i < this.FilterAR.length; i++) {
        console.log(this.FilterAR[i]);
        if (this.FilterAR[i].FGUID == this.FGUID) { return this.FilterAR[i]; }
    }
}

Open in new window

jQueryJavaScriptAJAX

Avatar of undefined
Last Comment
leakim971

8/22/2022 - Mon
leakim971

Not sure where you instanciate "o"
what about :

IPpage.prototype.LoadFilterList = function () {
...
   
    //add the user filters
   var o = this;
    $.ajax({
ASKER
skillilea

sorry I do that at the top

IPpage.prototype.LoadFilterList = function () {
   var o = this;
 ....


Here is my problem.

The array loads but then throughout the page I add(push) to the array and it looks like it creates another object and doesn't hold to:

this.FieldAR


Is it true that :  this.FieldAR.push(....)

should be GLOBAL at that point?

tnx
ASKER CERTIFIED SOLUTION
leakim971

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes