我正在尝试div.field
用父 div 包装每个包含一组 (s) 的对象.row
。Jquery 只允许我在同一行打开和关闭父 div。请帮忙!
$(document).ready(function(){
$.getJSON('WF-XML.php', function(data) {
JSON.stringify(data);
var prevCardCode = '';
$.each( data, function(index, element){
if (!(element['CardCode'] == prevCardCode)) {
var sum = element['payment_sum'];
$('#showdata').append('<div class="row"><div class="field">' + sum + '</div>');
}
prevCardCode = element['CardCode'];
$.each(element, function(i, element_detail){
if (!(i == 'InvKey' || i == 'PostDate' || i == 'City' || i == 'Objtype' || i == 'Block' || i == 'ZipCode' || i == 'Address' || i == 'payment_sum' || i == 'State1' || i == 'Country' || i == 'NumAtCard')) {
var detail = element_detail;
$('#showdata').append('<div class="field">' + detail + '</div>');
}
});
});
});
});
PHP
if (($handle = fopen('upload/BEN-new.csv', "r")) === FALSE) {
die('Error opening file');
}
$headers = fgetcsv($handle, 1024, ',');
$complete = array();
while ($row = fgetcsv($handle, 1024, ",")) {
$complete[] = array_combine($headers, $row);
}
fclose($handle);
echo json_encode($complete);
这是数据:
{"InvKey":"11704","CardCode":"1611704", "payment_sum": "1055.40"},
{"InvKey":"11703","CardCode":"1611703", "payment_sum": "550.00"}
它的打印是这样的:
<div class="row">
div class="field">1055.40</div>
</div>
<div class="field">1611704</div>
<div class="row">
<div class="field">550.00</div>
</div>
<div class="field">1611703</div>
我希望它像这样打印:
<div class="row">
<div class="field">1055.40</div>
<div class="field">1611704</div>
</div>
<div class="row">
<div class="field">550.00</div>
<div class="field">1611703</div>
</div>