Uploadify 说当我将 DOM 对象直接传递给它时它找不到占位符元素,但 Uploadifive 有效,为什么?



我试图用淘汰赛上载/上载,并一直遇到无法找到位置持有人元素的错误。仅在运行使用上传(flash)版本的IE时发生错误。其他浏览器很好,因为它们正在使用上传(HTML5)。为什么不在IE中工作?

html

<input type="file"  data-bind="imageUpload: images"  />

自定义绑定

        ko.bindingHandlers.imageUpload = {
        init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
            var uploadCallback = function (file, data, response) {
                valueAccessor().collection().add(JSON.parse(data));
            };
            window.setTimeout(function () {
              $(element).uploadifive({
                  'method': 'post',
                  'fileObjName': 'FileData',
                  'uploadScript': 'Image/Upload',
                  'onUploadComplete': uploadCallback,
                  'onFallback': function () {
                      $(element).uploadify({
                          'method': 'post',
                          'fileObjName': 'FileData',
                          'swf': '/Scripts/Uploadify/uploadify.swf',
                          'uploader': 'Image/Upload',
                          'onUploadSuccess': uploadCallback
                      });
                  }});
             }, 0);
           }
         }

问题是不将ID放在输入元素上并需要在超时函数中包装上载创建代码的组合。问题反映的代码将暂停将呼叫包装到$ .uploadify。这是因为上载在内部使用SWFUPLOAD,它将尝试通过ID查询输入元素。如果您不想在输入元素上放置ID属性,则还可以在上传脚本中添加一个小代码,该代码将生成ID。

这是我添加的

        //Add id to DOM object if it doesn't exist. 
        if (!$this.attr('id')) {
            $this.attr('id', 'uploadify' + uploadControlIdCounter);
            uploadControlIdCounter += 1;
        }

同一件事,周围有更多的上下文。

    /*
   Uploadify v3.1.1
   Copyright (c) 2012 Reactive Apps, Ronnie Garcia
   Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
   */
   (function($) {
   var uploadControlIdCounter = 0;
   // These methods can be called by adding them as the first argument in the uploadify plugin call
var methods = {
    init : function(options, swfUploadOptions) {
        return this.each(function() {
            // Create a reference to the jQuery DOM object
            var $this = $(this);
            //Add id to DOM object if it doesn't exist. 
            if (!$this.attr('id')) {
                $this.attr('id', 'uploadify' + uploadControlIdCounter);
                uploadControlIdCounter += 1;
            }

最新更新