![](/img/trans.png)
[英]Pass array to Javascript onClick function while adding links into a string?
[英]Adding onClick links into a JSON File Without javascript
因此,我试图模仿来自cytoscape库的数据可视化示例代码,并添加指向数据节点的链接。
这是例子
http://js.cytoscape.org/demos/cose-layout/
这是与示例关联的代码
https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/cose-layout
在github上的代码中有data.json文件,节点示例如下所示
[{
"data": {
"id": "605755",
"idInt": 605755,
"name": "PCNA",
"score": 0.006769776522008331,
"query": true,
"gene": true
},
"position": {
"x": 481.0169597039117,
"y": 384.8210888234145
},
"group": "nodes",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbed": false,
"grabbable": true,
"classes": "fn10273 fn6944 fn9471 fn10569 fn8023 fn6956 fn6935 fn8147 fn6939 fn6936 fn6629 fn7928 fn6947 fn8612 fn6957 fn8786 fn6246 fn9367 fn6945 fn6946 fn10024 fn10022 fn6811 fn9361 fn6279 fn6278 fn8569 fn7641 fn8568 fn6943"
},
我尝试添加
"links": {
"self": { "href": "https://www.google.com" }
},
和“链接”的变体:没有骰子。
我当时想知道,也许我可以获取ID并通过javascript添加链接,但是我没有成功。
$('#605755').dataTable( {
"columnDefs": [ {
"data": "download_link",
"render": function ( data, type, full, meta ) {
return '<a href="https://www.google.com"></a>';
}
} ]
} );
我想知道是否可以将其直接添加到JSON文件中,而无需使用javascript即可链接到外部站点。 当我打开检查时,它基本上只是显示一个画布而无法访问它内部的内容。 我绝对不是JSON的新手,因此向正确方向提供的任何帮助将不胜感激。
是的,可以使用fnDrawCallback
做到这fnDrawCallback
fnDrawCallback: function( oSettings,data,index ){
$('.linkClassName').on('click', function(event){
// do whatever u want
});
}
并将类名添加到您的链接
$('#605755').dataTable( {
"columnDefs": [ {
"data": "download_link",
"render": function ( data, type, full, meta ) {
return '<a class="linkClassName" href="https://www.google.com">data</a>';
}
} ]
} );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.