【问题标题】:meteor-upload custom template callback流星上传自定义模板回调
【发布时间】:2023-03-19 08:55:01
【问题描述】:

使用meteor-uploads 包的内置引导模板,上传完成时有一个方便的方法来进行模板特定的回调

<template name="home">
    {{> upload_bootstrap callbacks=myCallbacks }}
</template>`

Template.home.helpers({
    myCallbacks: function() {
        return {
            finished: function(index, fileInfo, context) { ... },
            ...
        }
    }
})

但对于我来说,在定义自定义模板described here 时,我无法弄清楚如何做同样的事情:

<template name="customUpload">
    <form method="POST" enctype="multipart/form-data">
        <input type="file" class="jqUploadclass" data-form-data='{{ submitData }}'>
        {{#with infoLabel}}
            {{ infoLabel}} <button class="start">StartUpload</button>
            <div style="width: 200px; height: 30px; border: 1px solid black">
                <div style="background: red; height: 30px; width: {{ progress }}">
                    {{ progress }}
                </div>
            </div>
        {{/with}}
    </form>
</template>

上传完成后,谁能帮我了解如何从自定义模板运行 myCallbacks 函数?

(例如,根据调用上传者的模板将 fileInfo 添加到不同的集合中)

【问题讨论】:

    标签: templates meteor upload callback


    【解决方案1】:

    这对我有用:

    HTML:

    <template name="myContainerTemplate">
      {{> customUpload multiple=true callbacks=myCallbacks}}
    </template>
    

    JavaScript:

    Template.myContainerTemplate.helpers({
        myCallbacks: function() {
            return {
                finished: function(index, fileInfo, context) { ... },
                ...
            }
        }
    });
    

    您必须将助手附加到父模板。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-16
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2016-08-14
      • 2016-07-09
      • 1970-01-01
      相关资源
      最近更新 更多