jquery - Json object not parsing correctly -


i have this page toward bottom can click on different categories parse applicable companies' logos. last item in array (the 'wesco' logo) supposed appear in "distribution" category appears in several categories. json file reads:

{"customers": [         {"customername": "3m", "imagelink": "/images/client-logos/logo-3m.jpg", "category": "healthcare,manufacturing","link":"http://www.3m.com"},         {"customername": "acxiom", "imagelink": "/images/client-logos/logo-acxiom.jpg", "category": "info-tech,services","link":"http://www.acxiom.com"},         {"customername": "adobe", "imagelink": "/images/client-logos/logo-adobe.jpg", "category": "info-tech","link":"http://www.adobe.com"},         {"customername": "alcatel-lucent", "imagelink": "/images/client-logos/logo-alcatel.jpg", "category": "telecommunications,info-tech","link":"http://www.alcatel-lucent.com"},         {"customername": "amdocs", "imagelink": "/images/client-logos/logo-amdocs.jpg", "category": "info-tech,services","link":"http://www.amdocs.com"},         {"customername": "arris", "imagelink": "/images/client-logos/logo-arris.jpg", "category": "info-tech,manufacturing","link":"http://www.arrisi.com"},         {"customername": "aspect", "imagelink": "/images/client-logos/logo-aspect.jpg", "category": "info-tech","link":"http://www.aspect.com"},         {"customername": "berylhealth", "imagelink": "/images/client-logos/logo-beryl.jpg", "category": "healthcare","link":"http://www.berylhealth.com"},         {"customername": "bisys", "imagelink": "/images/client-logos/logo-bisys.jpg", "category": "info-tech","link":"www.citibank.com"},         {"customername": "broadview networks", "imagelink": "/images/client-logos/logo-broadview.jpg", "category": "telecommunications","link":"http://www.broadviewnet.com"},         {"customername": "butler schein", "imagelink": "/images/client-logos/logo-butler.jpg", "category": "info-tech,healthcare,distribution","link":"http://www.butlerschein.com"},         {"customername": "carlton-bates", "imagelink": "/images/client-logos/logo-cbc.jpg", "category": "info-tech,distribution","link":"https://www.carltonbates.com"},         {"customername": "cisco", "imagelink": "/images/client-logos/logo-cisco.jpg", "category": "info-tech,manufacturing","link":"http://www.cisco.com"},         {"customername": "citrix", "imagelink": "/images/client-logos/logo-citrix.jpg", "category": "info-tech","link":"http://www.citrix.com"},         {"customername": "comverse", "imagelink": "/images/client-logos/logo-comverse.jpg", "category": "info-tech","link":"http://www.comverse.com"},         {"customername": "convergys", "imagelink": "/images/client-logos/logo-convergys.jpg", "category": "info-tech","link":"http://www.convergys.com"},         {"customername": "cypress communications", "imagelink": "/images/client-logos/logo-cypress.jpg", "category": "telecommunications","link":"http://www.cypresscommunications.net"},         {"customername": "deloitte", "imagelink": "/images/client-logos/logo-deloitte.jpg", "category": "services","link":"http://www.deloitte.com"},         {"customername": "ecova", "imagelink": "/images/client-logos/logo-ecova.jpg", "category": "services","link":"http://www.ecova.com"},         {"customername": "gartner", "imagelink": "/images/client-logos/logo-gartner.jpg", "category": "services","link":"http://www.gartner.com"},         {"customername": "ge healthcare", "imagelink": "/images/client-logos/logo-ge.jpg", "category": "healthcare,info-tech,manufacturing","link":"http://www.gehealthcare.com"},         {"customername": "henry schein", "imagelink": "/images/client-logos/logo-henry.jpg", "category": "info-tech,healthcare,distribution","link":"http://www.henryschein.com"},         {"customername": "hp", "imagelink": "/images/client-logos/logo-hp.jpg", "category": "info-tech,services","link":"http://www.hp.com"},         {"customername": "infor", "imagelink": "/images/client-logos/logo-infor.jpg", "category": "info-tech","link":"http://www.infor.com"},         {"customername": "intuit", "imagelink": "/images/client-logos/logo-intuit.jpg", "category": "info-tech","link":"http://www.intuit.com"},         {"customername": "ixia", "imagelink": "/images/client-logos/logo-ixia.jpg", "category": "info-tech,manufacturing","link":"http://www.ixiacom.com"},         {"customername": "jack henry", "imagelink": "/images/client-logos/logo-jack.jpg", "category": "info-tech","link":"http://www.jackhenry.com"},         {"customername": "marconi", "imagelink": "/images/client-logos/logo-marconi.jpg", "category": "telecommunications,info-tech","link":"#"},         {"customername": "mckesson", "imagelink": "/images/client-logos/logo-mckesson.jpg", "category": "healthcare,info-tech","link":"http://www.mckesson.com"},         {"customername": "mmodal", "imagelink": "/images/client-logos/logo-mmodal.jpg", "category": "info-tech,healthcare","link":"http://mmodal.com"},         {"customername": "motorola", "imagelink": "/images/client-logos/logo-motorola.jpg", "category": "info-tech,manufacturing","link":"http://www.motorola.com"},         {"customername": "nihon kohden", "imagelink": "/images/client-logos/logo-nihon.jpg", "category": "healthcare,manufacturing","link":"http://www.nihonkohden.com"},         {"customername": "owens , minor", "imagelink": "/images/client-logos/logo-om.jpg", "category": "healthcare,distribution","link":"http://www.owens-minor.com"},         {"customername": "paetec", "imagelink": "/images/client-logos/logo-paltec.jpg", "category": "telecommunications","link":"http://www.paetec.com"},         {"customername": "polyvision", "imagelink": "/images/client-logos/logo-polyvision.jpg", "category": "telecommunications,manufacturing,distribution","link":"http://polyvision.com"},         {"customername": "q2ebanking", "imagelink": "/images/client-logos/logo-q2.jpg", "category": "info-tech","link":"http://q2ebanking.com"},         {"customername": "rubbermaid", "imagelink": "/images/client-logos/logo-rubbermaid.jpg", "category": "info-tech,healthcare,manufacturing","link":"http://www.rubbermaid.com"},         {"customername": "wesco", "imagelink": "/images/client-logos/logo-wesco.jpg", "category": "distribution","link":"http://www.wesco.com"}      ] } 

the jquery is:

$.getjson('customers.json', function(data) {                 for(var index in definedcategoryarray){ //cycle through categories array                     for(var i=0; i<data.customers.length; i++){ //cycle through json data                         if (definedcategoryarray[index]==true){//if value in array true (item checked)                             console.log(data.customers[i].customername+ ' : ' + data.customers[i].category);                                 if(data.customers[i].category.indexof(',') != -1) //if there more 1 category, detect comma seperating them                                     categoriesplural = data.customers[i].category.split(',');                                    else //there 1 category                                     categoriesplural[0]=data.customers[i].category;                                 (var y = 0; y<categoriesplural.length; y++){                                         //console.log(categoriesplural[y]);                                         if(categoriesplural[y] == index){ //match category (from definedcategoryarray index) items in json object parse                                             $('ul#customers').append('<li class="' +data.customers[i].customername.replace(/\s+/g, '-') + '" id="'+data.customers[i].customername.replace(/\s+/g, '-')+'"><a href="'+ data.customers[i].link +'" title="'+ data.customers[i].customername +'" target="_blank"><img src="'+ data.customers[i].imagelink +'" alt="'+ data.customers[i].customername +'" /></a></li>');                                             checkduplicates(data.customers[i].customername.replace(/\s+/g, '-'));                                         }                                 }                         }                     }                 }             }).fail(function() { console.log( "error" ); }); 

when there multiple categories assigning categoriesplural entirely new set of elements, if there 1 category modifying first element of categoriesplural, assigned categoriesplural (except first element) still there.

instead of categoriesplural[0]=data.customers[i].category should categoriesplural=[data.customers[i].category]


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -