2

我想让ui版本的下载文件列表可以排序。呈现模板时,创建可排序列表的推荐方法会中断。我已尝试实施此处找到的建议: 上传后可排序的图像 - jQuery File Upload 但这只会使整个文件组可排序(作为一个组)。这是我的模板代码:

<!-- The template to display files available for upload -->
 <script id="template-upload" type="text/x-tmpl">
        {% for (var i=0, file; file=o.files[i]; i++) { %}
            <tr class="template-upload fade">
                <td>
                  <span class="preview"></span>
                </td>
                <td>
                    <p class="name">{%=file.name%}</p>
                    {% if (file.error) { %}
                        <div><span class="label label-important">Error</span> {%=file.error%}</div>
                    {% } %}
                </td>
                <td>
                    <p class="size">{%=o.formatFileSize(file.size)%}</p>
                    {% if (!o.files.error) { %}
                        <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
                    {% } %}
                </td>
                <td>
                    {% if (!o.files.error && !i && !o.options.autoUpload) { %}
                        <button class="button small radius success start">
                            <i class="icon-upload icon-white"></i>
                            <span>Start</span>
                        </button>
                    {% } %}
                    {% if (!i) { %}
                        <button class="button small radius secondary cancel">
                            <i class="icon-ban-circle icon-white"></i>
                            <span>Cancel</span>
                        </button>
                    {% } %}

 <p><label>Article ID: <input name="articleId[]" value="<?php echo $results['article']->id; ?>" required></label></p>
        <p><label>File Name: <input name="fileName[]" value="{%=file.name%}" required></label></p>
 </td>
            </tr>
        {% } %}
        </script>
        <!-- The template to display files available for download -->
        <script id="template-download" type="text/x-tmpl">
 <div class="template-download fade" ><ul id="sortable">
 {% $( "#sortable" ).sortable(); $( "#sortable" ).disableSelection(); %}
        {% for (var i=0, file; file=o.files[i]; i++) { %}

 {% 
 for (var j = 0; j < imageNames.length; j++) {
 if ( imageNames[j] == file.name ) {
 /*alert(imageNames[j]+'\n'+file.name);*/ %}


 <li class="ui-state-default">
 <p>i = {% print(i); %} </p>  

                    <span class="preview">
                        {% if (file.thumbnailUrl) { %}
                            <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a>
                        {% } %}
                    </span>

                    <p class="name">
                        <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
                    </p>
                    {% if (file.error) { %}
                        <div><span class="label label-important">Error</span> {%=file.error%}</div>
                    {% } %}

                    <span class="size">{%=o.formatFileSize(file.size)%}</span>

                    <button class="button small radius alert delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
                        <i class="icon-trash icon-white"></i>
                        <span>Delete</span>
                    </button>
                    <input type="checkbox" name="delete" value="1" class="toggle">
 <input type="hidden" name="sortOrder" value="{% print(i); %}">
                </li>


 {%
 }
 }
 %}

        {% } %}</ul></div>

        </script>
        <script>
  $(function() {
 $( "#sortable" ).sortable();
 $( "#sortable" ).disableSelection();
 $( ".files" ).sortable({
 revert: true
 });
  });
4

0 回答 0