在没有javascript

时间:2017-05-18 04:22:21

标签: javascript jquery json

所以我试图模仿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" }
 },

和"链接的变体":一些但没有骰子。

我很好,也许我可以通过javascript获取ID并添加链接,但我还没有成功。

$('#605755').dataTable( {
    "columnDefs": [ {
        "data": "download_link",
        "render": function ( data, type, full, meta ) {
            return '<a href="https://www.google.com"></a>';
        }
    } ]
} );

我想知道是否可以将其直接添加到JSON文件中,只需链接到没有javascript的外部网站。当我打开检查时,它基本上只显示一个画布,无法访问它看起来像画布内的内容。  我绝对是JSON的新手,所以对于正确方向的任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

确定您可以使用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>';
    }
} ]
} );