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 で入力要素を照会しようとするためです。入力要素に id 属性を付けたくない場合は、id を生成する小さなコードを uploadify スクリプトに追加することもできます。

これが私が追加したものです

        //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 に答える