【发布时间】:2012-11-30 06:28:25
【问题描述】:
我的页面顶部有字母“A-Z”。当用户单击一个字母时,我对 CFC 执行 AJAX 调用,该 CFC 根据所选字母执行缩略图目录的查询,并返回相应文件名的列表。
当列表返回到我在页面上的函数时,我使用split() 对文件名执行多个函数以提取某些信息。例如,文件名的格式如下:lastname_firstnameIMG_1234_RGB.jpg
我的目标是在我的 CFC 中提取姓氏、名字和数字,以便我可以标记缩略图图像并创建指向“真实”文件的链接以供下载,例如 lastname_firstnameIMG_1234_CMYK.tif 等...
最初,我使用split() 构建了我的 AJAX 函数来处理返回的列表,但我在 IE 中遇到了错误。为了缓解这个问题,我宁愿在我的 CFC 中执行字符串函数并返回准备好的数据。
在返回数据结构之前如何在 CFC 中执行字符串函数?
编辑 这个设置在 Safari 和 FF 中运行良好,但在 IE 中产生了错误。我尝试修改 split() 函数并取得了一些成功,但是当然,它在 FF 中无法正常工作。同样,我的目标是消除 javascript 字符串 mods 并在 CFC 中完成。
这是我的 CFC:
<cffunction name="List" access="remote" output="no" returntype="struct">
<cfargument name="letter" required="yes" type="string">
<cfset local = StructNew()>
<cfset local.response = StructNew()>
<cfset local.response["error"] = "">
<cfset local.response["message"] = "">
<cfset local.data = #arguments.letter# & "*.jpg">
<cfdirectory
action="list"
directory="#thumbsdir#"
recurse="true"
listinfo="name"
name="qFile"
filter="#local.data#"
/>
<cfset local.response["message"] = #qFile#>
<cfreturn local.response>
</cffunction>
还有我的 AJAX 函数(包含在 document.ready 函数中...):
$('.lastname').click(function(e){
e.preventDefault();
$('#emptymessage').hide();
$('#searching').show();
$('#content').html("");
var alpha = $(this).attr('id');
$.getJSON("cfcengine.cfc?method=List&returnformat=json&queryFormat=column",
{letter:alpha},
function(res, code) {
var s = "";
if(res.message.ROWCOUNT > 0) {
$('#searching').hide();
for(var i=0; i<res.message.ROWCOUNT; i++) {
//This is all the stuff I want to get rid of...
var theFile = res.message.DATA.Name[i]
var theLastName = theFile.split(/_(.+)/)[0];
var theRest = theFile.split(/_(.+)/)[1];
var theFirstNameAll = theRest.split(/_(.+)/)[0];
var theFirstName = theFirstNameAll.split(/(?:IMG)/)[0];
var theImageAll = theRest.split(/_(.+)/)[1];
var theImage = theImageAll.split(/_(.+)/)[0];
var bw = theLastName + '_' + theFirstName + 'IMG_' + theImage + '_BW.jpg';
var rgb = theLastName + '_' + theFirstName + 'IMG_' + theImage + '_RGB.jpg';
//Right now I'm just returning the name to the page until debugging is complete...
s += '<p>' + res.message.DATA.Name[i] + '<\/p>';
}
} else {
var s = "Sorry, nothing matched your search.";
}
$("#content").html(s);
//End response
}
//End getJSON
);
//End plist click function
});
【问题讨论】:
-
嗯...,-1?这是一个没有足够细节的畸形问题吗?只是好奇,所以我不会重复冒犯。
-
不知道为什么-1,我已经标记了
-
是的...+1..我很好奇为什么有人想对此投反对票...
-
@Richard,谢谢。我也不确定。我唯一能想到的就是看起来我正试图让某人为我编写代码。我不是,我只是不确定有什么好方法可以继续。我已经阅读了几篇关于
split()的帖子在 IE 中无法正常工作,所以我认为这可能与 CF 用户相关。
标签: javascript regex string coldfusion cfc