jqGrid二进制img不会显示

jqGrid binary img wont show up

本文关键字:显示 img 二进制 jqGrid      更新时间:2023-09-26

我使用一个标准函数在系统中检索图像,因为我们在数据库中有二进制文件,这在整个系统中都很好。

目前正在实现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",

函数getImage在您的代码中是未定义的,但我仍然认为您为getBinairy格式化程序选择了错误的方式。我假设您在格式化程序中对服务器进行异步Ajax调用。因此函数getBinairy返回""html变量的初始值)。

我建议您更改cellValue的格式,即通过填充主网格返回的列的数据格式。例如,数据可以是JSON编码的对象{src:.., width:... , height:... }{mimeType: ..., charset: ..., base64: ..., width: ... , height: ...}或一些其他对象。重要的是,输入数据应该是满的,格式化程序将仅基于数据生成<img>,而不需要任何Ajax调用。