3

このいまいましい配列に問題があります。私の情報をこのように掲載することでした。これを修正する方法はありますか?

prdpr=10.95^TBCC9^2^Shoes
prdsku=2.50^TDxa2^1^Pants
prdqn=7.50^Tasds^1^Hats
prdcatid=undefined^undefined^undefined^undefined

次のようになります。

prdpr=10.95^2.50^7.50
prdsku=TBCC9^TDxa2^Tasds
prdqn=2^1^1
prdcatid=Shoes^Pants^Hats

後で URL の文字列をつなぎ合わせます

var advid = "xxx";
var oid = "xxx";
var amt = "20.95";

// This array I cannot mess with, this is just an example
var OrderDetails = new Array();
OrderDetails[0] = ['10.95','2.50','7.50'];
OrderDetails[1] = ['TBCC9','TDxa2','Tasds'];
OrderDetails[2] = ['2','1','1'];
OrderDetails[3] = ['Shoes','Pants','Hats'];

var prdpr = '';
var prdsku = '';
var prdqn = '';
var prdcatid = '';

for(var x = 0; x < OrderDetails.length; x++) {
    var delim = "";
    if(x == 0){
        delim = "";
    }  else{
        delim = "^";
    }

    prdsku += delim + OrderDetails[x][0];
    prdpr += delim + OrderDetails[x][1];
    prdqn += delim + OrderDetails[x][2];
    prdcatid += delim + OrderDetails[x][3];
}

var output = '<div>Product Sku=' + prdsku + 'Item Cost=' + prdpr + 'Quanty=' + prdqn + 'Category=' + prdcatid + '</div>';
document.write(output);
4

1 に答える 1

1
var OrderDetails = new Array();
OrderDetails[0] = ['10.95','2.50','7.50'];
OrderDetails[1] = ['TBCC9','TDxa2','Tasds'];
OrderDetails[2] = ['2','1','1'];
OrderDetails[3] = ['Shoes','Pants','Hats'];

var delim = '^';

var prdpr = OrderDetails[0].join(delim);
var prdsku = OrderDetails[1].join(delim);
var prdqn = OrderDetails[2].join(delim);
var prdcatid = OrderDetails[3].join(delim);
于 2012-11-28T02:07:57.297 に答える