我正在尝试使用 cytoscape 用图形显示查询结果。我不是 javascript 专家,所以这可能只是一个语法错误,有人可以看一下我的代码吗?
<script type="text/javascript">
window.onload = function() {
// id of Cytoscape Web container div
var div_id = "cytoscapeweb";
// NOTE: - the attributes on nodes and edges
// - it also has directed edges, which will automatically display edge arrows
var xml = '\
<graphml>\
<key id="label" for="all" attr.name="label" attr.type="string"/>\
<key id="weight" for="node" attr.name="weight" attr.type="double"/>\
<graph edgedefault="directed">\
<node id="1">\
<?php echo "<data key=\"label\">$prot</data>\\\n";?>
<data key="weight">2.0</data>\
</node>
<?php $count=2;?>
<?php while($row = mysql_fetch_array($result)){
echo "<node id=\"$count\">\\";
echo "<data key=\"label\">$row['interactor']</data>\\";
echo "<data key=\"weight\">1.0</data>\\";
echo "</node>\\";
echo "<edge source="1" target=\"$count\">\\";
echo "<data key=\"label\">$prot to $row['interactor']</data>\\";
echo "</edge>\\";
$count++;
}?>
</graph>\
</graphml>\
';
最佳答案
直接用JS写的XML字符串使用反斜杠来保护行尾。您的 PHP 代码也输出反斜杠,但后面没有回车。因此,要么在每个 "\\"
之后插入 "\n"
,要么从 PHP 代码中删除每个 "\\"
。
一个建议:当出现问题时,还要在浏览器中查看页面的 HTML 源代码。这个错误在那里应该很明显。并学习使用网络浏览器的 JS 控制台(例如,在 Chrome 和 Opera 中,Ctrl-Shift-i 打开带有错误面板的开发人员工具栏)。
关于php - 从 php 代码创建一个 cytoscape 树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13603053/