我使用一个标准函数来检索系统中的图像,因为我们在数据库中有二进制文件,这在整个系统中工作得很好。
目前正在实现jqGrid,并且在使用当前结构时存在一些问题,因为图像不能显示,并且jquery结构($obj = $("<div>");
)不可用。
现在我尝试实现来获取二进制图像,但是它不会显示,当使用静态url时,它可以工作并且图像数据正在被检索。
$.extend($.fn.fmatter, {
getBinairy: function (cellValue, options) {
//var object = $();
var width = 50;
var html = "";
getImage(cellValue).success(function (data) {
$.each($.parseJSON(data.d), function (idx, obj) {
p_image = obj.img;
p_type = obj.type;
p_width = obj.width;
p_height = obj.height;
});
var _width = width / p_width;
var _height = _width * p_height;
html = "<img src='data:" + p_type + ";base64," + p_image + "' />";
//object = $("<img/>", {
// src: "data:" + p_type + ";base64," + p_image,
// width: width,
// height: _height
//});
//object.append($img);
});
//var html = "<img src='img/test/20131027_132450.jpg' />";
return html;
},
至于我认为fn加载"html“太快,我不能理解其他原因,但不知道如何避免这一点。
有什么帮助吗?
-更新
var ip = "";
var station = "";
return $.ajax({
type: "POST",
url: "services/general.asmx/SendBinairy",
data: JSON.stringify({ session: 'ed6d1cc6-82f9-46e8-91bb-eae341a771cf', ip: ip, station: station, id: id }), ///, _filter: JSON.stringify(_json) }),
contentType: "application/json; charset=utf-8",
dataType: "json",
loaderror: function (xhr, status, error) {
},
success: function (data) { }
});
-更新
"dataset": [
{
"id": 5,
"suffix_type_id": 0,
"sexe_type_id": 1146,
"first_name": "Varvara",
"middle_name": "",
"last_name": "D",
"full_name": "Varvara D",
"company_name": "",
"nickname": "",
"birthday": "1983-12-18",
"age": 31,
"language_type_id": 6,
"relation_type_id": 0,
"job_status_type_id": 404,
"nationality_type_id": 0,
"last_online": "",
"last_online_app_id": 0,
"profile_image": 24,
"profile_rating": 7.000,
"number_contacts": 0,
"number_applications": 0,
"address_id": 0,
"address_1": null,
"address_2": null,
"address_3": null,
"number": 0,
"add": null,
"postal_code": null,
"city": null,
"city_type_id": 0,
"latitude": null,
"longitude": null,
"state": null,
"state_type_id": 0,
"country_type_id": 0,
"address_type_id": 0,
"image": [
{
"file_id": 24,
"binary": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIB
这就是我如何将数据添加到jqGrid中
$("#" + grid_id).jqGrid({
loadonce: true,
type: "POST",
url: "services/general.asmx/HelloWorld",
postData: { q: session },
datastr: colD,
contentType: "application/json; charset=utf-8",
datatype: "jsonstring",
colModel: colM,
rowNum: 10,
rowList: [10, 20, 30],
pager: '#' + grid_id,
sortname: 'id',
viewrecords: true,
sortorder: "desc",
发布于 2014-09-14 10:13:36
您的代码中没有定义函数getImage
,但是我仍然认为您为getBinairy
格式化程序选择了错误的方式。我假设您在格式化程序中对服务器进行异步Ajax调用。因此,函数getBinairy
返回""
( html
变量的初始值)。
我建议您更改cellValue
的格式-通过填充主网格返回的列的数据格式。例如,数据可以是JSON编码的对象、{src:.., width:... , height:... }
或{mimeType: ..., charset: ..., base64: ..., width: ... , height: ...}
等。重要的是,输入数据应该是完整的,格式化程序将只根据数据生成<img>
,而不需要任何Ajax调用。
https://stackoverflow.com/questions/25831831
复制相似问题