2

我试图让您使用带有淘汰赛的uploadify/uploadifive,并不断收到有关无法找到占位符元素的错误。该错误仅在运行使用 uploadify(flash) 版本的 IE 时发生。其他浏览器很好,因为它们使用的是 uploadifive(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);
           }
         }
4

1 回答 1

1

问题是没有在输入元素上放置 id 并且需要将 uploadify 创建代码包装在超时函数中。问题中的代码反映了对 $.uploadify 的调用的超时。这是因为uploadify 在内部使用了swfupload,它会尝试通过id 查询输入元素。如果您不想在 input 元素上放置 id 属性,您还可以在 uploadify 脚本中添加一些代码,该脚本将生成一个 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;
            }
于 2012-11-08T03:14:40.963 回答