Javascript:确定数组是否包含位置

时间:2013-08-14 08:05:53

标签: javascript

我有一个文件列表,对于每个文件,在click事件中,我得到文件名并解析文件名并获得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);
                }
            });
            }
        });
});

0 个答案:

没有答案
相关问题