1

我的表单允许用户选择一个目录来查看其中包含的文件:

(文件.cfm)

<form action="#buildURL('main.files')#" method="post">

        <!--- Show the subfolder path, unless already at top level --->
        <cfif subfolderPath EQ "">
            <h2>You are at the top level.</h2>
        <cfelse>
            <h2>Current Folder: #subfolderPath#</h2>
        </cfif>

        <!--- Provide a drop-down list of subfolder names --->
        Select folder:
        <select name="subfolderPath" onChange="this.form.submit()">
            <!--- Provide an option to go up one level to the parent folder, --->
            <!--- unless already at the BaseFolder --->
            <cfif listLen(subfolderPath, "/") gt 0>
                <cfset parentFolder = listDeleteAt(subfolderPath, listLen(subfolderPath, "/"), "/")>
                <option value="#parentFolder#">[parent folder]</option>
            </cfif>

            <!--- For each record in the query returned by <cfdirectory> --->
            <cfloop query="DirectoryQuery">
                <!--- If the record represents a subfolder, list it as an option --->
                <cfif Type eq "Dir">
                    <option value="#subfolderPath#/#Name#">#Name#</option>
                </cfif>
            </cfloop> 
        </select>

        <!--- Submit button to navigate to the selected folder --->
        <input type="submit" value="go">
    </form> 

显示文件时,有一个删除功能会调用另一个页面:

<td align="absmiddle"><a href="#buildUrl('main.deleteFile?filename=#name#&folder=#rereplace(subFolderPath, '/','')#')#" onClick="alert('Are you sure you want to delete this file?')"><img src="/art/assets/images/delete.png" title="delete file" /></a></td>

在 deleteFile 页面 (deleteFile.cfm) 上,文件被删除:

<cfset local.filePath = ExpandPath( ".\upload\views\files\#rereplace(url.folder, '/','')#\" ) />
    <cffile action="delete"
            file="#local.filePath##url.filename#"
    />

然后用户被送回上一页:

<cflocation url="#buildUrl('main.files')#" />

但不在刚刚删除文件的目录的同一视图中。如何将用户返回到文件页面并维护他所在目录的视图?

4

1 回答 1

2

我能想到几种方法

首先,您可以使用 AJAX 调用删除操作文件。成功完成后,从当前页面中删除该元素。这是一种奇特的方式,但可能很难实现,因为看起来您可能对此有些陌生。

其次,您可以将当前页面的上下文发送到删除文件(subFolderPath 变量),在重定向时将其添加到 cflocation。看起来你已经有了 url.folder 变量,所以你可以这样做:

<cflocation url="#buildUrl('main.files', "subfolderPath=#rc.folder")#" />

看起来您使用的是 FW/1,所以我假设 'buildURL()' 像宣传的那样工作,并且您的 url 和表单变量在rc范围内。

从 cflocation 返回到初始页面后,您将希望将选择放回您选择的文件夹中。在创建<option>标签的循环中,添加检查以查看是否应选择选项。我通常会做这样的事情:

<option value="..." <cfif listLast(rc.subFolderPath,"\") EQ name>selected</cfif>>#name#</option>
于 2012-11-09T18:01:15.547 回答