Ext.define('ImageModel', {
extend: 'Ext.data.Model',
fields: ['PicID', 'PicUploadedDateTime','PicData']
});
var ImgStore = Ext.create('Ext.data.JsonStore', {
model: 'ImageModel',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'get-image.php',
baseParams: { //here you can define params you want to be sent on each request from this store
mainid: 'value1',
startdate: 'value2',
enddate: 'value3'
},
reader: {
type: 'json',
root: 'images'
}
}
});
var listView = Ext.create('Ext.grid.Panel', {
region: 'west',
id : 'imagelist',
title: 'Select Image',
width: 200,
split: true,
collapsible: true,
floatable: false,
title:'Select Image',
renderTo: Ext.getBody(),
store: ImgStore,
multiSelect: true,
viewConfig: {
emptyText: 'No images to display'
},
columns: [
{
text: 'Date Time Uploaded',
//xtype: 'datecolumn',
//format: 'Y-m-d H:i:s',
flex: 65,
width: 100,
dataIndex: 'PicUploadedDateTime'
}]
});
listView.on('selectionchange', function(view, nodes){
Ext.getCmp('displayimage') = nodes[0].get("PicData") // display the image on here
//when listview selected the image,will display the image at here.
});
我创建了一个列表视图,当列表视图上的选择更改时,将显示图像Ext.getCmp('displayimage')
。
nodes[0].get("PicData")
是选择
的图像数据图像数据是blob值(都是JPEG十六进制值),如何从extjs显示图像?
更新
这是我的显示图像代码
button.on('click', function(){
if (!win) {
win = Ext.create('widget.window', {
title: 'View Image',
closable: true,
closeAction: 'hide',
width: 600,
minWidth: 350,
height: 550,
layout: {
type: 'border',
padding: 5
},
items:[
listView,
{
region: 'center',
//xtype: 'tabpanel',
minheight: 350,
items: [{
//title: 'Bogus Tab',
xtype : 'image',
id : 'displayimage',
}]
},
{
region: 'north',
margin : "5 0 5 0",
//xtype: 'tabpanel',
minheight: 350,
items: [dr]
}]
});
在我将代码更改为之后
Ext.getCmp('displayimage').src = 'data:image/jpeg;base64,'+nodes[0].get("PicData") //
Image corrupt or truncated
这是我从萤火虫得到的错误消息,但我可以确定我的二进制数据是正确的,因为我尝试使用 python 将其转换为 .jpeg 文件
这是来自数据库的 .jpeg 示例 blob 值(二进制字符串), http:
//pastebin.ca/raw/2314500