webbutter
11-04-2009, 07:16 AM
Hey all -
Came into this problem creating a portfolio site. I do an ajax request to query my server to return different types of information like id, date, title, medium, size, description.. etc.. these all return fine. in php i separated each row of the result using "^", and then split the results in javascript using the same symbol.
var results = xmlHttp.responseText.split("^");
I then split the individual aspects of each piece ( that were separated with a comma ) using;
for (i = 0; i < numresults; i++) {
var singlerow = results[i].split(',');
ids.push(singlerow[0]);
titles.push(singlerow[1]);
dates.push(singlerow[2]);
so i have arrays like ids[] that contain, in the same order, attributes to individual portfolio pieces. So i thought i would create an object for each piece by creating a function like:
function createPortfolioObject(indexnum){
this.ida = ids[indexnum];
this.title = titles[indexnum];
this.date = dates[indexnum];
this.description = descriptions[indexnum];
this.size = sizes[indexnum];
this.medium = mediums[indexnum];
this.thumbup = thumbups[indexnum];
this.thumbover = thumbovers[indexnum];
this.mainimage = mainimages[indexnum];
alert(""+this);
return this;
}
So i created these objects using a simple loop like:
function makePortfolio(x){
var digitalHolder = new Array();
var w = parseInt(x.length) - 1;
for (var m = 0; m < w; m++){
digitalHolder[m] = createPortfolioObject(m);
}
displayPortfolio(digitalHolder);
}
(the variable x, is the titles array, just to keep a count on how many pieces are in this section). The problem comes when I pass the digitalHolder array into the next function, the digitalHolder Array holds 22 items, but they are all the same. The next function intends to do something like this...
function displayPortfolio(holder){
alert(""+holder[19].title);
for(n=0; n < holder.length; n++){ makediv(holder[n].title,holder[n].thumbup,holder[n].thumbover,holder[n].mainimage);
}
}
function makediv(divid,upimg,overimg,mainimg){
var diva = document.createElement("div");
diva.id = divid;
diva.style.backgroundImage = "url(portfolioUploads/digital/"+upimg+")";
diva.className ="portfolioThumb";
document.getElementById('portfolioContent').appendChild(diva);
}
I feel like it has something to do with storing the creating objects into an array.. but i'm not too sure, any help would be greatly appreciated. Thanks in advance.
Came into this problem creating a portfolio site. I do an ajax request to query my server to return different types of information like id, date, title, medium, size, description.. etc.. these all return fine. in php i separated each row of the result using "^", and then split the results in javascript using the same symbol.
var results = xmlHttp.responseText.split("^");
I then split the individual aspects of each piece ( that were separated with a comma ) using;
for (i = 0; i < numresults; i++) {
var singlerow = results[i].split(',');
ids.push(singlerow[0]);
titles.push(singlerow[1]);
dates.push(singlerow[2]);
so i have arrays like ids[] that contain, in the same order, attributes to individual portfolio pieces. So i thought i would create an object for each piece by creating a function like:
function createPortfolioObject(indexnum){
this.ida = ids[indexnum];
this.title = titles[indexnum];
this.date = dates[indexnum];
this.description = descriptions[indexnum];
this.size = sizes[indexnum];
this.medium = mediums[indexnum];
this.thumbup = thumbups[indexnum];
this.thumbover = thumbovers[indexnum];
this.mainimage = mainimages[indexnum];
alert(""+this);
return this;
}
So i created these objects using a simple loop like:
function makePortfolio(x){
var digitalHolder = new Array();
var w = parseInt(x.length) - 1;
for (var m = 0; m < w; m++){
digitalHolder[m] = createPortfolioObject(m);
}
displayPortfolio(digitalHolder);
}
(the variable x, is the titles array, just to keep a count on how many pieces are in this section). The problem comes when I pass the digitalHolder array into the next function, the digitalHolder Array holds 22 items, but they are all the same. The next function intends to do something like this...
function displayPortfolio(holder){
alert(""+holder[19].title);
for(n=0; n < holder.length; n++){ makediv(holder[n].title,holder[n].thumbup,holder[n].thumbover,holder[n].mainimage);
}
}
function makediv(divid,upimg,overimg,mainimg){
var diva = document.createElement("div");
diva.id = divid;
diva.style.backgroundImage = "url(portfolioUploads/digital/"+upimg+")";
diva.className ="portfolioThumb";
document.getElementById('portfolioContent').appendChild(diva);
}
I feel like it has something to do with storing the creating objects into an array.. but i'm not too sure, any help would be greatly appreciated. Thanks in advance.