实时代码示例:cytoscape.js初始化-不完整? [英] live code examples: cytoscape.js initialization -- incomplete?

查看:295
本文介绍了实时代码示例:cytoscape.js初始化-不完整?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为cytoscape.js的新手,我可能会缺少明显的东西.如果是这样,请原谅我.

我正在研究提供的第一个示例此处:

来自此页面

提供了三个文件-HTML,CSS,JavaScript-以及这三个文件在加载到我的浏览器中后会创建一个正在运行的示例的印象.

但是HTML似乎不完整,可能有两种方式:

  1. 需要通过脚本标签包含jsbin页面上的JavaScript
  2. 在我可以看到的任何地方都没有定义变量cy,导致在控制台中出现此错误消息:对象#cy没有方法cytoscape

关于该错误消息的堆栈溢出搜索可以指向非常好的cy.js文档,但是,las,我还是一头雾水:在哪里初始化"cy"对象?

最重要的是,在哪里可以找到一个完整的工作示例,该示例对像我这样的原始初学者很有用,我可以仔细研究并研究一些东西,直到我开始理解这种编程风格的逻辑并利用这个非常好的图书馆?

谢谢!

解决方案

我真的不知道您的JavaScript是什么. jQuery的知识水平,但似乎您可能需要稍作练习.

  1. 是的,如果您引用的是以下标记:

    <script src="http://cytoscape.github.io/cytoscape.js/api/cytoscape.js-latest/cytoscape.min.js"></script>

    这确实是必要的,因为它是cytoscape.js的基础,例如,库本身允许将方法cytoscape添加到变量#cy中,正如您在第二点中提到的那样. /p>

  2. 变量#cydiv本身. jQuery以此方式用#引用对象ID.所以:

    <div id="cy"></div>

    可以称为$(#cy"). Wich在库本身中添加了cytoscape函数.

我认为这个实时示例确实不错,尽管您链接的是用cytoscape.js的基本结构和初始化更为基础和适当.我建议您以jQuery(这门课程对我来说真的很清楚)来认识并阅读 cytoscape.js文档,其中包含许多丰富的示例.

Being brand new to cytoscape.js, I may be missing something obvious. Please forgive me if that is so.

I am studying the first example offered here:

reached from this page

Three files are offered -- HTML, CSS, JavaScript -- along with the impression that these three will, when loaded into my browser, create a running example.

But the HTML seems to be incomplete, possibly in two ways:

  1. the JavaScript on the jsbin page needs to be included via a script tag
  2. the variable cy is not defined anywhere that I can see, leading to this error message in the console: Object #cy has no method cytoscape

A stack overflow search on that error message points back to the very fine cy.js documentation, but alas, I am still in the dark: where do I initialize the "cy" object?

And best of all, where can I find a complete working example, useful for such a raw beginner as myself, something I can pore over and study until I begin to grasp the logic of this style of programming, and make use of this very fine library?

Thanks!

解决方案

I really don't know what's your JavaScript & jQuery knowledge level, but it seems you may need to practice it all a little.

  1. Yes, if you're referring to the following tag:

    <script src="http://cytoscape.github.io/cytoscape.js/api/cytoscape.js-latest/cytoscape.min.js"></script>

    This is indeed necessary, as it is the basis of cytoscape.js, the library itself, wich allows, for instance, add the method cytoscape to the variable #cy, as you mentioned in your second point.

  2. The variable #cy is the div itself. jQuery refers to objects IDs this way, with #. So:

    <div id="cy"></div>

    Can be referred as $("#cy"). Wich adds the cytoscape function to it is the library itself.

I think that this live example is really good, although the one you linked is more basic and appropriate to get known with the basic structure and initialization of cytoscape.js. I suggest you to get known with jQuery (this course was really clear to me) and read the cytoscape.js documentation, which is full of rich examples.

这篇关于实时代码示例:cytoscape.js初始化-不完整?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆