problem with array
i am trying to display images in slideshow. in that i am using array of image paths.but the array is taking only firstvalue(firstimage) my javascript is
var res;
var sp = new Array();
var hdnvalue = a = document.getElementById('HiddenField4').value;
var imgArr = hdnvalue.split(';');
for (var count = 0; count < imgArr.length; count++) {
if (count == 0)
res = '[' + imgArr[count];
else if (count != imgArr.length - 1)
res += '","","",""],[' + imgArr[count];
else
res += '","","",""],[' + imgArr[count] + '","","",""]';
}
sp = res.split(';');
alert(sp);
var mygallery2 = new fadeSlideShow({
wrapperid: "fadeshow2",
dimensions: [568, 313],
imagearray: [ * * sp * * ],
//<--array of images!],
displaymode: {
type: 'auto',
pause: 2500,
cycles: 0,
wraparound: false
},
persist: false,
//remember last viewed slide and recall within same session?
fadeduration: 500,
//transition duration (milliseconds)
descreveal: "always",
togglerid: "fadeshow2toggler"
})
where sp is a开发者_运维问答n array where i am storing imagepaths. is this the correct way to assign an array like
imagearray: [ sp ],You are storing an array in the first index of an array.
If you want to store the array, than reference it
imagearray: sp,
Just use:
// ...
imagearray: sp,
// ...
You've already built an array, so just refer to its name.
(This is not really an answer but a comment, but I need to write longer)
It's quite confusing what you are doing there.
You seem to creating a string in the variable res
. What's the idea there? What are you exactly trying to achieve in the loop?
Then you split that string at semicolons (sp = res.split(';');
), but that string can't contain any semicolons.
can it be you need to create an array of arrays where the inner arrays contain of one non-empty string and three empty strings? In that case you probably want something like this:
var imgArr = hdnvalue.split(';');
var sp = [];
for (var count = 0; count < imgArr.length; count++) {
sp.push([imgArr[count], "", "", ""]);
}
var mygallery2 = new fadeSlideShow({
wrapperid: "fadeshow2",
dimensions: [568, 313],
imagearray: sp,
/* ... etc. ... */
精彩评论