开发者

JS: How to make the val() real-time

开发者 https://www.devze.com 2023-02-07 03:12 出处:网络
Im having a issue here. Im using Valum´s file uploader, and i want to include a param. This param is开发者_如何学运维 albumID, aID, which should have the value of the album you selected. Although the

Im having a issue here. Im using Valum´s file uploader, and i want to include a param. This param is开发者_如何学运维 albumID, aID, which should have the value of the album you selected. Although the javascript, that makes the button and where you make the settings, executes at document.ready. And because of this, it runs the albumPicker.val() immediatly, and therefore sets the albumPicker from the start to "1" (first album in the <select> i have is 1) and even if you pick another and upload a file, it wont take the changed one.

Here's the code:

   $(document).ready(function(){     
            var album = $('#albumPicker').val()
        var uploader = new qq.FileUploader({
            element: document.getElementById('file-uploader-demo1'),
            action: 'php.php',
                allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
            debug: true,
                params: {
                aID : $('#albumPicker').val()
                },
                onComplete: function(id, fileName, responseJSON){ 
                    if(responseJSON.success){
                    $( '#'+$('#albumPicker').val() ).attr('src', [responseJSON.path].join(''));
                    }
                },
        });           
    });

Although the onComplete where it replaces a image, works just fine with the albumPicker.val(), because first when its completed the file upload it checks for the val().

What can I do about this? How can i solve this?


To change params based on the state of your app, use

uploader.setParams({
   anotherParam: 'value' 
});

So on uploadButton.click just overwrite the parameter with it's realtime value. If that's not possible just hook into

onSubmit: function(id, fileName){},

you might still be able to change the parameters to reflect real time values on submit. Good luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消