jquery - php array merge JSON array data is not getting displayed while executing each loop -
i have 2 php array $pricelist & $product. after merge these array json encoded got json array follows.
my php array as:
array ( [0] => array ( [pricelist] => array ( [price_id] => 2 [price_name] => abc [date_time] => 2015-07-06 16:22:56 [dealer_type] => dealer [purpose] => dealer [status] => active ) ) [1] => array ( [product] => array ( [cat_id] => 1 [subcat_id] => 3 [brand_id] => 1 [p_code] => pp12567 [name] => akai [model_no] => [specification] => color tv [color] => [quality] => [size] => [p_unavail] => 1 [demo_avail] => 0 [brochure] => [status] => active ) [productprice] => array ( [id] => 154 [p_code] => pp12567 [price_id] => 1 [quantity] => 233 [purchase_price] => 344.00 [selling_price] => 44.00 [discount_price] => 33.00 [tax] => 5.00 [datetime] => 2015-07-23 15:47:11 ) [productsubcategory] => array ( [subcat_id] => 3 [cat_id] => 1 [subcat_name] => samsung [status] => active ) [productcategory] => array ( [cat_id] => 1 [cat_name] => electronics [cat_type] => product [status] => active ) )
here json array:
[ { "pricelist": { "price_id":"2", "price_name":"abc", } }, { "product": { "cat_id":"1", "subcat_id":"3", "p_code":"pp12567", "name":"akai" }, "productsubcategory": { "subcat_id":"3", "cat_id":"1", "subcat_name":"samsung" }, "productcategory": { "cat_id":"1", "cat_name":"electronics" } } ]
and each loop follows:
function render_price_list_details(resp){ table = ''; $.each(resp,function(indx,obj){ table += '<tr>'; table += '<td>'+ parseint(indx+1) +'</td>'; table += '<td>'+ obj.productcategory.cat_name +'</td>'; table += '<td>'+ obj.productsubcategory.subcat_name +'</td>'; table += '<td>'+ obj.product.name +'</td>'; table += '<td>'+ obj.pricelist.price_name +'</td>'; table += '</tr>'; }); $("tbody#product_price").append(table); }
table not getting displayed when loop executed.
if alert resp shows like: [object,object],[object,object]
the append part outside loop/each function. hence gets appended when entire loop done.
$.each(resp,function(indx,obj){ //reset table here again table = '<tr>'; table += '<td>'+ parseint(indx+1) +'</td>'; table += '<td>'+ obj.productcategory.cat_name +'</td>'; table += '<td>'+ obj.productsubcategory.subcat_name +'</td>'; table += '<td>'+ obj.product.name +'</td>'; table += '<td>'+ obj.pricelist.price_name +'</td>'; table += '</tr>'; //append now. $("tbody#product_price").append(table); });
Comments
Post a Comment