troubleshooting Question

help with array return

Avatar of skillilea
skillilea asked on
JavaScriptAJAXjQuery
3 Comments1 Solution171 ViewsLast Modified:
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]; }
    }
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros