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>