0

我有一个文件列表,对于每个文件,在单击事件时,我获取文件名并解析文件名并获取extension类型:

extension = $('#'+id_href).text().split('.').pop();

现在,ajax应该进行调用以获取有关当前文件扩展名的数据。

如果我的扩展数组中已经保存了扩展数据,我想阻止 ajax api 调用。

我的扩展数组看起来像a[extension_1] = html_data_1, a[extension_2] = html_data_2

我想检查位置是否extension_1已经存在,如果不存在,则应进行 ajax 调用来检索数据;

我应该用什么替换if(!array_extension[extension])线?

var array_extension = new Array();

ImgAjaxLoader = "$url_img"+'ajax-loader.gif';
ImgI = "$url_img"+'info_icon.png';
$("html").live("click", function() {
    $(".info_box").hide();
});
$(".info").live("click",function(e){
    e.stopPropagation();
    var elem = $(this);
    $(".info_box").hide();
    position = $(this).offset();
    var id = 'container_tooltip';
    var id_img = $(this).attr('id');
    var id_href = $(this).attr("id").replace("image_","href_");
    $('#'+id_img).attr('src',ImgAjaxLoader);
    $('#'+id).toggle(100, function() {
        if($(this).css('display') == 'block') {
            extension = $('#'+id_href).text().split('.').pop();
            //if(!array_extension[extension])
            $.ajax({
                url: "$url",
                data: { document_id:elem.attr('document_id') },
                success: function (response) {
                    //console.log(response);
                    response = JSON.parse(response);
                    array_extension[response.extension] = response.html;
                    $('#'+id).html(response.html);
                    $('#'+id).css({'top':(position.top-110)+'px','left':(position.left+30)+'px'});
                    $('#'+id_img).css({'width':'20px','height':'20px',"padding":"0px"});        
                    $('#'+id_img).attr('src',ImgI);
                }
            });
            }
        });
});
4

0 回答 0