Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 字符串呈现项中的箭头函数_Javascript_Reactjs_Ag Grid - Fatal编程技术网

Javascript 字符串呈现项中的箭头函数

Javascript 字符串呈现项中的箭头函数,javascript,reactjs,ag-grid,Javascript,Reactjs,Ag Grid,全部,, 我正在努力处理以下代码: rowRenderer = (e) => { debugger; return e.data?.fileName ? '<a class="documentLink" onclick={() => \'' + console.log('\'' + e.data.fileName + '\'') + '\'}>' + e.data.fileName + '</a>' :

全部,, 我正在努力处理以下代码:

rowRenderer = (e) => {
    debugger;
    return e.data?.fileName ? 
        '<a class="documentLink" onclick={() => \'' + console.log('\'' + e.data.fileName + '\'') + '\'}>' + e.data.fileName + '</a>' : 
        e.data.name;
}
rowRenderer=(e)=>{
调试器;
返回e.data?.fileName?
“\”“+console.log(“\”“+e.data.fileName+”\”“)+'\'}>“+e.data.fileName+”:
e、 data.name;
}
这将在控制台中正确打印文件名,但在标记中,文件名显示为“'undefined'}>file-sample_500kB.doc”-我知道转义有问题,但我无法看到它 以上代码只是一个测试-原始代码应为:

    rowRenderer = (e) => {
    debugger;
    return e.data?.fileName ? 
        '<a class="documentLink" onclick={() => this.downloadFileClickHandler(\'' + JSON.stringify(e.data) + '\')}>' + e.data.fileName + '</a>' : 
        e.data.name;
}
rowRenderer=(e)=>{
调试器;
返回e.data?.fileName?
'this.downloadFileClickHandler(\''+JSON.stringify(e.data)+'\')}>'+e.data.fileName+'':
e、 data.name;
}

我想在单击按钮时调用一个函数,因为您+字符串,所以您的函数只返回一个字符串。如果您使用的是ReactJS,则应返回如下组件:

rowRenderer = (e) => {
    return e.data?.fileName ? <a className={"documentLink"} onClick={() => console.log(e.data.fileName)} > {e.data.fileName}</a> : e.data.name;
}
rowRenderer=(e)=>{
返回e.data?.fileName?console.log(e.data.fileName)}>{e.data.fileName}:e.data.name;
}
我这样修复它:

    rowRenderer = (params) => {
    return params.data?.fileName ?
        `<a class="documentLink" onClick="document.getElementById('download_${params.data.id}').click();">${params.data.name}</a>` :
        params.data.name;
}
然后我在网格中创建了一个新列,其中有“headerClass:‘emptyHeader’”,并且:

cellRenderFunction:(参数)=>{
const rowContent=参数数据;
返回(
this.downloadFileClickHandler(e,rowContent)}>{rowContent.name}
);
},

尝试使用文字模板而不是引号,这会使引号更具可读性,更不容易出现语法错误。您为什么需要使用react来执行此操作?
            optionalGridProps={{
                autoGroupColumnDef: {
                    cellRendererParams: {
                        suppressCount: true,
                        innerRenderer: (param) => this.rowRenderer(param)
                    },
            }
cellRendererFunction: (params) => {
                const rowContent = params.data;
                return (
                    <div id={`download_${rowContent.id}`} key={rowContent.id} className={'link hidden'} onClick={(e) => this.downloadFileClickHandler(e, rowContent)}>{rowContent.name}</div>
                );
            },