Jquery 执行每个循环时,不会显示php数组合并JSON数组数据
我有两个php数组$pricelist和$product。在将这些数组与json编码的数组合并后,我得到了如下所示的json数组 我的php数组如下所示:Jquery 执行每个循环时,不会显示php数组合并JSON数组数据,jquery,json,loops,Jquery,Json,Loops,我有两个php数组$pricelist和$product。在将这些数组与json编码的数组合并后,我得到了如下所示的json数组 我的php数组如下所示: Array ( [0] => Array ( [PriceList] => Array ( [price_id] => 2 [price_name] => ab
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
)
)
这是我的JSON数组:
[
{
"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"
}
}
]
我的每个循环如下所示:
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);
}
函数呈现\价格\列表\详细信息(resp){
表='';
美元。每个(分别,功能(indx,obj){
表+='';
表+=''+parseInt(indx+1)+'';
表+=''+obj.ProductCategory.cat_name+'';
表+=''+obj.ProductSubCategory.subcat\u name+'';
表+=''+obj.Product.name+'';
表+=''+obj.PriceList.price_name+'';
表+='';
});
$(“车身#产品#价格”)。附加(表格);
}
执行循环时未显示表
如果我提醒resp,则其显示如下:
[对象,对象],[对象,对象]附加部分在循环/每个函数之外。因此,当整个循环完成时,它会被追加
$.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 it now.
$("tbody#product_price").append(table);
});
$。每个(分别,功能(indx,obj){
//再次在此重置表格
表='';
表+=''+parseInt(indx+1)+'';
表+=''+obj.ProductCategory.cat_name+'';
表+=''+obj.ProductSubCategory.subcat\u name+'';
表+=''+obj.Product.name+'';
表+=''+obj.PriceList.price_name+'';
表+='';
//现在添加它。
$(“车身#产品#价格”)。附加(表格);
});
附加部分在循环/每个函数之外。因此,当整个循环完成时,它会被追加
$.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 it now.
$("tbody#product_price").append(table);
});
$。每个(分别,功能(indx,obj){
//再次在此重置表格
表='';
表+=''+parseInt(indx+1)+'';
表+=''+obj.ProductCategory.cat_name+'';
表+=''+obj.ProductSubCategory.subcat\u name+'';
表+=''+obj.Product.name+'';
表+=''+obj.PriceList.price_name+'';
表+='';
//现在添加它。
$(“车身#产品#价格”)。附加(表格);
});
我们可以在调用render\u price\u list\u details()。您似乎走错了方向。我们可以使用调用render\u price\u list\u details()
的代码吗?您可以编辑多个产品的json吗。看来你走错了路。还是不工作。。json数组的问题。。我已将两个数组合并为一个数组。。如果我对单个数组进行编码,那么它工作正常。。无论何时对合并数组进行编码,它都不工作。仍然不工作。。json数组的问题。。我已将两个数组合并为一个数组。。如果我对单个数组进行编码,那么它工作正常。。无论何时对合并数组进行编码,它都不起作用。