我之前询问如何将cytoscape作为依赖项远程加载。@GBE提供了以下答案
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/2.7.10/cytoscape.js"></script>
所以我制作了一个 HTML
文件,并且把来自 cytoscape 的 introductory example 原封不动地复制过来(将其用 <script>code</script>
包裹)。然而结果什么也没有呈现。为什么?下面是方便起见的代码。
小问题:为什么源代码被包含在中括号内:
<script src="stuff"></script>
其它所有内容都是什么?
<script>代码</script>
?
介绍示例
<script>
var cy = cytoscape({
container: document.getElementById('cy'), // container to render in
elements: [ // list of graph elements to start with
{ // node a
data: { id: 'a' }
},
{ // node b
data: { id: 'b' }
},
{ // edge ab
data: { id: 'ab', source: 'a', target: 'b' }
}
],
style: [ // the stylesheet for the graph
{
selector: 'node',
style: {
'background-color': '#666',
'label': 'data(id)'
}
},
{
selector: 'edge',
style: {
'width': 3,
'line-color': '#ccc',
'target-arrow-color': '#ccc',
'target-arrow-shape': 'triangle'
}
}
],
layout: {
name: 'grid',
rows: 1
}
});
</script>