0

私はjqgridを使用しています。行を追加するときに、サーバーにファイルをプッシュしたいです。

多くの投稿を読みましたが、実際の例が見つかりません。

多くの例は、jquery 1.5 以降では機能しません。

私は次のように評議する人々を見つけました:

http://www.jainaewen.com/files/javascript/jquery/iframe-post-form.html#api

http://malsup.com/jquery/form/#file-upload

しかし、これをjqgridで使用する方法がわかりません。

誰かが jqgrid でファイルをアップロードするソリューションの完全な例を教えてくれますか?

感謝、

4

1 に答える 1

0

さて、私は見つけました:

<script type="text/javascript" src="/static/jqueryform/jquery.form.js"></script>

<script type="text/javascript"> $(function(){

 $("#citype").jqGrid({  url:"/api/citype/getdata",
    datatype:'json',
    mtype:'POST',
    colNames:['No', 'Name', 'Icon'],
    colModel :[
      {         name:'id',
                index:'id',
                width:55,
                editable:false,
                key:true,
                hidden:true
      },
      {
                name:'name',
                index:'name',
                width:55,
                editable:true
      },
      {
                name:'icon',
                index:'icon',
                edittype:'file',
                width:80,
                align:'right',
                editable:true},
    ],
    pager:'#pager',
    rowNum:10,
    rowList:[10,20,30],
    sortname:'citype_id',
    sortorder:'desc',
    viewrecords:true,
    gridview:true,
    caption:'List',
    useDataProxy: true,
    dataProxy :  function (opts, act) {
            opts.iframe = true;
            var $form = $('#FrmGrid_citype');    //use name of the grid
            //Prevent non-file inputs double serialization
            var ele = $form.find('INPUT,TEXTAREA,SELECT').not(':file');
            ele.each(function () {
                            $(this).data('name', $(this).attr('name'));
                            $(this).removeAttr('name');
                            });

            //Send only previously generated data + files
            $form.ajaxSubmit(opts);
            //Set names back after form being submitted
            setTimeout(function () {
                            ele.each(function () {
                                    $(this).attr('name', $(this).data('name'));
                                    jQuery("#citype").trigger('reloadGrid');
                                    });
                            }, 200);
    },
    editurl:"/submit"


  });

// Action Option   jQuery("#citype").jqGrid('navGrid','#pager',
    {}, //options
    {    // edit options
        closeAfterEdit:true,
        height:280,
        reloadAfterSubmit:true,
        closeOnEscape : true,
        useDataProxy: true,
        onInitializeForm : function(formid){
                    $(formid).attr('method','POST');
                    $(formid).attr('action','');
                    $(formid).attr('enctype','multipart/form-data');
                }
    },
    {    // add options
        closeAfterAdd:true,
        height:280,
        reloadAfterSubmit:true,
        closeOnEscape : true,
        useDataProxy: true,
        onInitializeForm : function(formid){
                    $(formid).attr('method','POST');
                    $(formid).attr('action','');
                    $(formid).attr('enctype','multipart/form-data');
                }
    },
    {   // del options
        reloadAfterSubmit:true
    },
    {} // search options   );
于 2013-08-09T01:27:01.640 に答える