Link to home
Start Free TrialLog in
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

Avatar of leakim971
leakim971
Flag of Guadeloupe image

Not sure where you instanciate "o"
what about :

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

ASKER

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
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial