2013-02-15 83 views
4

我已将jQuery-File-Upload代码添加到我使用Knockout.js的页面。该代码使用JavaScript模板引擎,该模板运行良好,但是有谁知道是否有方法使用Knockout的模板?Knockout.js模板和jQuery文件上传

uploadTemplate和downloadTemplate看起来像函数指针。

根据文档... uploadTemplate和downloadTemplate方法应该返回jQuery集合对象或呈现的上传/下载模板的字符串表示形式。

我不确定从哪里开始。

+0

你问他们的论坛? https://groups.google.com/forum/#!forum/jquery-fileupload – WiredPrairie 2013-02-15 18:00:31

回答

4

我们遇到同样的问题。我们将knockout与jQuery模板(我们很快将用jsRender替换)结合使用。 JQuery-File-Upload(blueImp)的下载/上传模板是Django templates。我将这些模板像应用程序中的挖空模板一样线程化。我们已经封装在淘汰赛定制绑定jQuery的文件上传功能:

ko.bindingHandlers.fileupload = { 
    update: function (element, valueAccessor) { 
     var options = valueAccessor() || {}; 

     //initialize 
     $(element).fileupload(options); 
    } 
}; 

我们使用这样的:

<div id="fileuploadcontrol" 
    data-bind="fileupload: { 
        url: [UPLOAD URL], 
     maxFileSize: [MAX FILE SIZE], 
     acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, 
     completed: function (e, data) { 
      $.each(data.files, function (index, file) { 
       //Stuff to do with uploaded files 
      } 
     } 
       }"> 

     <div class="fileupload-buttonbar"> 
    <!-- buttons --> 
      //STUFF 

      <!-- The global progress bar --> 
      //STUFF 
    </div> 
</div> 
+0

这是一些疯狂的绑定 – 2013-09-12 03:28:29