简体   繁体   English

值文件上传器的多个实例

[英]multiple instances of valums file uploader

I'm trying to get multiple instances of valum file uploader working on my site. 我正在尝试在我的网站上使用valum文件上传器的多个实例。 It works great with one instance but anytime I loop over initialization code, wanting multiple buttons I don't see any buttons. 它在一个实例上很好用,但是每当我遍历初始化代码时,想要多个按钮,我都看不到任何按钮。 Here's the code: 这是代码:

<cfoutput query="getTopics">

<script>        
    function createUploader(){            
        var uploader = new qq.FileUploader({
            element: document.getElementById('file-uploader#refTopicID#'),
            action: 'components/ProjectBean.cfc',
            params: {method: 'Upload',
                    topicID: #refTopicID#,
                    count: #Evaluate("session.#refTopicAbv#Count")#,
                    topicName: '#refTopicAbv#'
                    },
            encoding: 'multipart'
        });           
    }

    // in your app create uploader as soon as the DOM is ready
    // don't wait for the window to load  
    window.onload = createUploader;     
</script>

<div class="row" id="file-uploader#refTopicID#">        
</div>

Any idea how to get multiple instance? 任何想法如何获取多个实例? Thanks in advance! 提前致谢!

You're creating a javascript function inside of a loop. 您正在循环内创建javascript函数。 In other words you're defining it multiple times. 换句话说,您要多次定义它。

Instead you should move the createUploader function outside of your loop. 相反,您应该将createUploader函数移出循环。 And within the loop, simply call it multiple times for each of your topics. 在循环中,只需为每个主题多次调用它。

Something like this: 像这样:

<script>        
    function createUploader(elementID, topicID, topicCount, topicName){            
        var uploader = new qq.FileUploader({
            element: document.getElementById(elementID),
            action: 'components/ProjectBean.cfc',
            params: {method: 'Upload',
                    topicID: topicID,
                    count: topicCount,
                    topicName: topicName
                    },
            encoding: 'multipart'
        });           
    }   
</script>

<cfoutput query="getTopics">
<script>        
    createUploader('file-uploader#getTopics.refTopicID#', #getTopics.refTopicID#, #session[getTopics.refTopicAbv & "Count"]#, '#getTopics.refTopicAbv#');   
</script>

<div class="row" id="file-uploader#getTopics.refTopicID#"> </div>
</cfoutput>

NB: I'm assuming the values all come from your query getTopics , so I've prefixed them with the query name to scope them properly. 注意:我假设所有值都来自您的查询getTopics ,所以我在查询名称前加上了前缀以适当地限制它们的范围。 This isn't usually essential, but it's good practice for performance reasons (among other things). 这通常不是必需的,但出于性能方面的考虑(除其他事项外),这是一种很好的做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM