Reputation: 7707
I'm trying to get a multidimensional object output from .map(), the final format I would like to get something like { "key" : { key : value, key : value }, "key" { key : value, key : value }, ... }
.
Here's some code http://pastie.org/1524749
I've tried in different ways without success since when I send it through ajax, I get array undefined in PHP
var arrData = $('#orDetColProducts .lineBottomRow').map(function(){
intRef = $(this).find('._ref').text();
intPrice = $(this).find('._intPrice').text();
intQuantity = $(this).find('.existStock').val();
if (intRef && intQuantity) {
return '{' + intRef + ' : { quantity : ' + intQuantity + ', price : ' + intPrice + '}' + '}';
}
});
Upvotes: 1
Views: 2954
Reputation: 342635
Try this:
var arrData = $('#orDetColProducts .lineBottomRow').map(function() {
var intRef = $(this).find('._ref').text();
var intPrice = $(this).find('._intPrice').text();
var intQuantity = $(this).find('.existStock').val();
var tmp = {};
if (intRef && intQuantity) {
tmp.intRef = { quantity: intQuantity, price: intPrice };
}
return tmp;
}); // chain .get() to convert to array
Upvotes: 2