火狐firebug显示错误SyntaxError: missing ) after argument list的问题

博主在开发中使用easyui datagrid的formatter时遇到参数传递问题。起初一种传递方式以为是括号不匹配,检查无果;改成另一种方式后报row undefined错误,花费大量时间调试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在开发过程中遇到这个问题,在使用easyui datagrid中的formatter时遇到的,起初是这样传递参数的,openDir()函数在后面

//这样传递参数是错误的

function rowformater(value,row,index)
{

return "<a href='#' onclick='javascript:openDir("+row+");'" + ">打开</a>";

}


以为是括号不匹配的错误,检查了半天也没发现不匹配,结果花费了好长时间进行研究调试,再改成这样

//结果报row undefined,这样传递参数也是错误的

function rowformater(value,row,index)
{
return "<a href='#' onclick='javascript:openDir(row);'" + ">打开</a>";
}



所以就通过一个变量,先将row赋值给这个变量,再传递过去,正确传参代码如下

<pre name="code" class="javascript">function rowformater(value,row,index)
{
    parm = row;
    if(row.isDirOrFile == "file"){
        return "<a href='<%=request.getContextPath() %>/filedownload/download.htm?filePath=" + row.filePath + "&fileName=" + row.fileName + "&fileType=" + row.fileType + "'" + "\">下载</a>";
    } else{
        return "<a href='#' onclick='javascript:openDir(parm);'" + ">打开</a>";  //
    }
}

openDir()函数如下:

function openDir(row){
	$('#downloadDatagrid').datagrid({    
		url:$WEB_ROOT_PATH + '/crawle/fileList.htm?fileDto.filePath=' + row.filePath,    
	}); 
	$('#downloadDatagrid').datagrid('hideColumn', 'isDirOrFile');
}
对应的jsp中代码如下:

<table id="downloadDatagrid" class="easyui-datagrid" style="width: 500px;height: 300px;"
	data-options="fit:true,rownumbers:true,singleSelect:true,fitColumns:true,sortName:'fileLength',onDblClickRow:function(row){findFiles(row);}"> 
	    <thead>   
	        <tr>   
	       	    <th data-options="field:'filePath',checkbox:true">文件路径</th>
	            <th data-options="field:'fileName',width:100">文件名</th>   
	            <th data-options="field:'fileLength',width:100">文件大小</th>
	            <th data-options="field:'fileType',width:50,<span style="color:#FF0000;">formatter:rowformater</span>">操作</th>
	            <th data-options="field:'isDirOrFile',width:100"></th>
	        </tr>   
	    </thead> 
</table>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值