分配基准64转换的图像从JSON [英] Assigning Base 64 converted image from JSON

查看:215
本文介绍了分配基准64转换的图像从JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,code这是我用来表示JSON的细节,所有detailsshowing除了正常我image.When尝试以显示其在图像中不显示图像。

JSON方法

  Ext.Ajax.request({
    网址:App.gvars.apiurl +'ShowItemsByItemID /用户ID ='+ App.gvars.userid +'/ ITEMID ='+ ITEMID,//网址:this.getUrl()
    方法:GET,
    useDefaultXhrHeader:假的,
    withCredentials:真实,
    成功:函数(响应){
        VAR respObj = Ext.JSON.de code(response.responseText);
        Ext.getCmp('myitemname')的setValue(respObj [0] .itemName)。
        Ext.getCmp('myitemdesc')的setValue(respObj [0] .itemDesc)。
        Ext.getCmp('myitemprice')的setValue(respObj [0] .itemPrice)。
        Ext.getCmp('myshopurl')的setValue(respObj [0] .itemAddress)。
        Ext.getCmp('myproductpic')的setValue(respObj [0] .itemImage)。 //这里的形象得到
    },
    故障:功能(响应){
        警报(response.responseText);
    }
    });

在这里,面板

  {
    的xtype:'板',
    高度:100像素,
    停靠:'底',
    HTML:'< D​​IV ALIGN =中心的风格=填充顶:30PX;>< IMG SRC =资源/ IMG / icon1.pngID =myproductpic/>&安培; NBSP;&放; NBSP;&安培; NBSP;&安培; NBSP;< IMG SRC =资源/ IMG / icon2.pngID =myimglocation/>< / DIV>'
  }

如何显示的base64在myproductpic转换图像area.Please帮我解决。


解决方案

  Ext.getCmp()仅适用于煎茶触摸组件,在这里你应该使用的document.getElementById()

还设置数据的类型,源

 的document.getElementById('myproductpic')SRC =数据:图像/ JPEG; BASE64,+ respObj [0] .itemImage;

Here the code which i have used to show the details from JSON , All detailsshowing properly except image.When i try to show the image its not showing in the image.

JSON METHOD

    Ext.Ajax.request({
    url:  App.gvars.apiurl + 'ShowItemsByItemID/userID='+App.gvars.userid+'/itemID='+itemID, // url : this.getUrl(),
    method: "GET",
    useDefaultXhrHeader: false,
    withCredentials: true,
    success: function (response) {
        var respObj = Ext.JSON.decode(response.responseText);
        Ext.getCmp('myitemname').setValue(respObj[0].itemName);
        Ext.getCmp('myitemdesc').setValue(respObj[0].itemDesc);
        Ext.getCmp('myitemprice').setValue(respObj[0].itemPrice);
        Ext.getCmp('myshopurl').setValue(respObj[0].itemAddress);
        Ext.getCmp('myproductpic').setValue(respObj[0].itemImage);  //Here the image getting       
    },
    failure: function (response) {
        alert(response.responseText);
    }
    });

Here the Panel

  {
    xtype: 'panel',
    height:'100px',
    docked: 'bottom',
    html:'<div align="center" style="padding-top:30px;"><img src="resources/img/icon1.png" id="myproductpic" />&nbsp;&nbsp;&nbsp;&nbsp;<img src="resources/img/icon2.png" id="myimglocation" /></div>'
  }     

How to show base64 converted image in the 'myproductpic' area.Please help me to solve

解决方案

Ext.getCmp() works only for sencha touch components, here you should use 

document.getElementById()

Also set the type of data in source

document.getElementById('myproductpic').src = "data:image/jpeg;base64,"+respObj[0].itemImage;

这篇关于分配基准64转换的图像从JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆