簡體   English   中英

如何在不添加額外按鈕的情況下重新初始化Uploadify腳本?

[英]How can I re-initialize Uploadify script without adding extra button?

我在這里引導您完成以下過程:

第1步
1.從下拉列表中選擇產品
2.表單中填充了數據
3.隱藏的ID獲取所選項目中的產品ID
4.初始化Uploadify並檢索產品ID。 一個上載按鈕已添加到表單。

第2步
1.從下拉列表中選擇新產品
2.用數據重新填充表格
3.隱藏的ID是所選商品的新產品ID。
4.初始化Uploadify並檢索產品ID。 新的上載按鈕添加到窗體。

現在我被兩個按鈕卡住了。 不完全是我想要的。

我可以檢查是否添加了按鈕,因此沒有重新初始化按鈕,但是Uploadify腳本將不會檢索新的產品ID(我需要其他商品)。

有什么想法可以解決這個小問題嗎?

這是我的uploadify函數:

function initUploadify()
{ 
    // If button is already added, do not add it again.
    // But this will not retrieve new productID.
    if( jQuery('#brand_btnBrowseLogoQueue').length < 1)
    {
        jQuery('#txtBoxFileName').css({'position':'relative', 'top':'-9px'});
        jQuery("#brand_btnBrowseLogo").uploadify({
            'uploader'       : 'wp-content/plugins/uploadify/uploadify.swf',
            'script'         : 'wp-content/plugins/uploadify/uploadify.php',
            'folder'         : 'brand',
            'fileExt'        : '*.jpg;*.jpeg;*.png',
            'auto'           : true,
            'multi'          : false,
            'method'         : 'POST',
            'height'         : '30',
            'width'          : '100',
            'buttonImg'      : 'path/to/img/btn_browse_101x30px.png',
            'scriptData'     : {'productID':jQuery("#productID").val()},
            onComplete       : function(event, queueID, fileObj, response, data) { 
                //This makes the json response readable                
                data = eval("(" + response + ")");
                //Update logo image
                setLogo(jQuery("#brandID").val(),data.fileName);
            }
        });
    }    
}

如果您只需要更改productID則應根據插件文檔進行操作

//initialize uploadify when first product is selected
if( jQuery('#brand_btnBrowseLogoQueue').length < 1) {
   ...
} else {
    //uploadify already initialized just change the productId
    $("#brand_btnBrowseLogo").uploadifySettings(
        'scriptData',
        {'productID': jQuery("#productID").val()}
    );
}

在創建新按鈕之前,您是否嘗試過刪除上一個按鈕?

if($('#brand_btnBrowseLogoQueue').length != 0)
    $('#brand_btnBrowseLogoQueue').remove();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM