meteor-upload自定义模板回调 [英] meteor-upload custom template callback

查看:240
本文介绍了meteor-upload自定义模板回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 meteor-uploads 软件包的内置引导模板,有一种方便的方法上传完成时具有模板特定的回调

With the meteor-uploads package's built-in bootstrap template, there is a handy way to have template specific callbacks when the upload is finished

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

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

但是在我的生活中,我无法弄清楚在定义自定义模板时如何做同样的事情此处描述

But for the life of me I can't figure out how to do the same thing when defining a custom template 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函数?

Could somebody help me understand how to run the myCallbacks function from the custom template after the upload is complete?

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

( say for example adding the fileInfo to different collections depending on which template the uploader is called from )

推荐答案

这适用于我:

HTML:

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

JavaScript:

JavaScript:

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

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

You have to attach the helper to the parent template.

这篇关于meteor-upload自定义模板回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆