1

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 + '}' + '}';
  }
});

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, thanks a lot for your atention! I see your point, but when I try to use this arrData on jquery.ajax I get array undifined on php. The output on console.log is [Object { intRef={...}}, Object { intRef={...}}]; I'll keep trying, based on your tip!
Also tryed to tested with var arrData = {"66949":{ quantity:7,price:200}, "343235":{ quantity: 12, price: 100}}; and this one works fine on php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.