[英]Object property returns part of literal
I am new to JavaScript Objects and i got a list of object and in that object there is a property called signature which is BLOB, I am trying to decode it so I can display it as image, but when I use it, I am unable to use it.upon debugging in console, the returned item is a number but it has following structure 我是JavaScript对象的新手,我有一个对象列表,并且在该对象中有一个称为签名的属性,它是BLOB,我试图对其进行解码,以便可以将其显示为图像,但是当我使用它时,我无法要使用它。在控制台中调试时,返回的项目是一个数字,但具有以下结构
"{
"signature": "/9j/4AA"
but when I do console.log(typeof + deca);
但是当我做
console.log(typeof + deca);
it says number, following is my code 它说数字,以下是我的代码
for (const sign of result){
const deca = atob(sign.signature);
console.log(typeof + deca);
console.log(deca) I get this console.log(deca)我明白了
and using it to display like 并用它来显示像
<img *ngFor="let sign of selectedUser"
[src]="sign.imageData"
alt="">
Do I need to use trim or slice to cut off the "{ "signature":
part or I am doing something wrong? 我是否需要使用修剪或切片来剪掉
"{ "signature":
部分,或者我做错了什么?
this happens because of the +
operator, which automatically makes the variable a number
. 发生这种情况的原因是
+
运算符,该运算符自动使变量成为number
。
https://jsfiddle.net/n97ssLma/ https://jsfiddle.net/n97ssLma/
var test = "test" alert(typeof test) //string alert(typeof + test) //number
to display your blob as an image do the following: 要将blob显示为图像,请执行以下操作:
var image = document.createElement('img'); image.src="data:image/gif;base64,R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw=="; image.width=100; image.height=100; image.alt="here should be some image"; document.body.appendChild(image);
Using Javascript to Display Blob 使用Javascript显示Blob
updated your fiddle: https://jsfiddle.net/jt5ks76z/1/ 更新了您的小提琴: https : //jsfiddle.net/jt5ks76z/1/
example using atob method: 使用atob方法的示例:
https://jsfiddle.net/jt5ks76z/4/ https://jsfiddle.net/jt5ks76z/4/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.