Javascript 通过JSON.Stringify EXIF处理图像数据的每个循环
我有一个图像,一旦我点击它,它就会显示得更大,旁边有EXIF数据。 我使用JSON.strigify获取EXIF数据,然后我需要显示该字符串中的任何内容,以添加到HTML中带有Javascript 通过JSON.Stringify EXIF处理图像数据的每个循环,javascript,jquery,html,json,Javascript,Jquery,Html,Json,我有一个图像,一旦我点击它,它就会显示得更大,旁边有EXIF数据。 我使用JSON.strigify获取EXIF数据,然后我需要显示该字符串中的任何内容,以添加到HTML中带有id='makeAndModel'的标记中 我想对每个箭头函数使用它,但我不确定具体如何使用 `<div id="imageContainer"></div> <div id="myModal" class="modal"> <span class
id='makeAndModel'
的
标记中
我想对每个箭头函数使用它,但我不确定具体如何使用
`<div id="imageContainer"></div>
<div id="myModal" class="modal">
<span class="close">×</span>
<img class="modal-content" id="current">
<pre>Make and model: <span id="makeAndModel"></span></pre>
</div>`
<--Taking the src attribute and creating the images-->
let $modal = $('.modal')
let $img = $("#imageContainer img");
$img.click(function(){
$('.modal-content').attr('src', $(this).attr('src'));
$modal.css('display', 'block')
<--EXIF data-->
var imgCurrent = document.getElementById('current');
EXIF.getData(imgCurrent,function(){
let result = $('#makeAndModel')
let make= JSON.stringify(EXIF.getAllTags(this));
});
let $makeAndModel = $('#makeAndModel');
$makeAndModel.text(`${make}`)
})
`
&时代;
设$modal=$('.modal')
设$img=$(“#imageContainer img”);
$img.单击(函数(){
$('.modal content').attr('src',$(this.attr('src'));
$modal.css('display'、'block')
var imgCurrent=document.getElementById('current');
EXIF.getData(imgCurrent,函数(){
让结果=$(“#makeAndModel”)
让make=JSON.stringify(EXIF.getAllTags(this));
});
让$makeAndModel=$(“#makeAndModel”);
$makeAndModel.text(`${make}`)
})
`
当前在控制台中,let make
的输出是objectlet make={
"定位":一,,
“YCBC公司定位”:1,
“决议”:72,
“YResolution”:72,
“决议单位”:2,
“制造”:“三星”,
“型号”:“SM-G965F”,
“软件”:“G965FXXU2CSB9”,
“日期时间”:“2019:03:18:29:28”,
“出口点”:213,
“GPSInfoIFDPointer”:833,
“曝光时间”:0.02,
“FNumber”:2.4,
“曝光程序”:“正常程序”
,“等速等级”:160,
“ExifVersion”:“0220”,
“DateTimeOriginal”:“2019:03:18:29:28”,
“数字化日期时间”:“2019:03:18:29:28”,
}
预期的输出应该是
品牌和型号:
定位:1,
YCBC公司选址:1,
X决议:72,
Y解决方案:72,
诸如此类,比如当你点击一张图片的属性->详细信息选项卡时,类似的事情可能会发生
let $modal = $('.modal')
let $img = $("#imageContainer img");
$img.click(function() {
$('.modal-content').attr('src', $(this).attr('src'));
$modal.css('display', 'block')
var imgCurrent = document.getElementById('current');
EXIF.getData(imgCurrent, function() {
let result = $('#makeAndModel')
let make = EXIF.getAllTags(this);
let props = Object.entries(make).map(([property, value]) => {
return `${property}: ${value}`;
});
result.text(props.join('\n'));
});
})
JSON.stringify
返回一个字符串-它没有forEach
方法-坦率地说,我看不出您试图使用JSON stringify实现什么-也许您只是想要let make=EXIF.getAllTags(这个)代码>-因为这很有可能成为阵列,所以不确定您认为$(“#makeAndModel”+”)
有什么作用。。。但是它不这样做让make=EXIF.getAllTags(this)
返回[object object]
。$('#makeAndModel'+'')
是个错误,是的,我已经删除了整个make.forEach(element=>{$('#makeAndModel'+'')
[对象]
是吗?你怎么知道?无论如何…JSON.stringify
是如何创建JSON字符串的…JSON.parse是如何从JSON字符串创建一个普通的ol'javascript对象…EXIF.getAllTags(这个)到底是什么
return?对,所以make
是一个对象,而不是数组…只有数组具有forEach
-您可以使用OBJECT.entries(make.forEach([键,值])=>…)