【问题标题】:Assigning Base 64 converted image from JSON从 JSON 分配 Base 64 转换后的图像
【发布时间】:2013-09-20 09:45:42
【问题描述】:

这里是我用来显示 JSON 细节的代码,所有细节都正确显示,除了图像。当我尝试显示图像时,它没有显示在图像中。

JSON 方法

    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);
    }
    });

面板在这里

  {
    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>'
  }     

如何在“myproductpic”区域显示base64转换后的图像。请帮我解决

【问题讨论】:

    标签: json extjs sencha-touch-2 base64


    【解决方案1】:
    Ext.getCmp() works only for sencha touch components, here you should use 
    
    document.getElementById()
    

    还要设置源中的数据类型

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

    【讨论】:

    • @Fazil 让我测试一下。在此处发布该 base64 字符串
    • 你可以从 pastebin.com/yVkn4rsf 获取字符串
    • @Fazil 抱歉.. 我错过了在您的代码中看到的一些内容.. 查看更新
    猜你喜欢
    • 2020-02-21
    • 1970-01-01
    • 2017-10-24
    • 2018-03-23
    • 2020-11-27
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多