使用热毛巾模板(Knockout和Durandal)控制Dropzone

时间:2014-04-23 10:51:36

标签: knockout.js requirejs durandal hottowel dropzone.js

我在Hot Towel模板中加载Dropzone控件时遇到问题我使用了dropzone-amd-module并将其作为依赖项包含在内

require.config({
    paths: {
        'text': '../Scripts/text',
        'durandal': '../Scripts/durandal',
        'plugins': '../Scripts/durandal/plugins',
        'transitions': '../Scripts/durandal/transitions',
        'dropzone': '../Scripts/dropzone-amd-module'

    }
});

和我的dashboard.js

define(['services/logger','dropzone'], function (logger,Dropzone) {
    var title = 'Home';
    var vm = {
        title: title
    };

    return vm;

    //#region Internal Methods
    function activate() {

           Dropzone.options.dropzoneJsForm = {

            //prevents Dropzone from uploading dropped files immediately
            autoProcessQueue: false,

            init: function () {
                var submitButton = document.querySelector("#submit-all");
                var myDropzone = this; //closure

                submitButton.addEventListener("click", function () {
                    myDropzone.processQueue(); //tell Dropzone to process all queued files
                });

            },
            addRemoveLinks: true

        };
        logger.log(title + ' View Activated', null, title, true);
        return true;
    }
});

但是我收到了这个错误

  

未捕获错误:无法加载路由模块(仪表板/仪表板)。   详细信息:模块名称"发射器"尚未加载上下文:_。   使用require([])

1 个答案:

答案 0 :(得分:0)

我按照这些步骤来解决问题

1-包含dropzone.js脚本在索引页面中的require.js之前 2-不要将它包含在main.js中作为require配置依赖项
3-在附加事件中以编程方式创建dropzone元素,如下所示

 function attached(view) {
        var myDropzone = new Dropzone("#dropzoneJsForm", { url: "/file/post", autoProcessQueue: false });
    }

所以我的控制器如下

define(['services/logger'], function (logger) {
    var title = 'Details';


    var vm = {
        activate: activate,
        title: title,
        attached: attached,
    };

    return vm;

    function attached(view) {
        var myDropzone = new Dropzone("#dropzoneJsForm", { url: "/file/post", autoProcessQueue: false });
    }

    //#region Internal Methods
    function activate() {


       logger.log(title + ' View Activated', null, title, true);
        return true;
    }
});