cytoscape.js & meteor 简单示例不起作用

cytoscape.js & meteor simple example doesnt work

  1. 我添加到 meteor cytoscape 中:infinitedg:cytoscape
  2. 我有非常基本的流星应用程序:

hello.js http://pastebin.com/2frsHc9g hello.htmlhttp://pastebin.com/10EYyJ74

但我做不到

这是我在 Web 浏览器控制台中看到的错误:

on rendered zavolana hello.js:9 ss [object Object] debug.js:41 Exception from Tracker afterFlush function: debug.js:41 TypeError: Cannot read property 'addEventListener' of undefined at CanvasRenderer.registerBinding (infinitedg_cytoscape.js:17127) at CanvasRenderer.load (infinitedg_cytoscape.js:17283) at new CanvasRenderer (infinitedg_cytoscape.js:13419) at $$.fn.core.initRenderer (infinitedg_cytoscape.js:7527) at new $$.Core (infinitedg_cytoscape.js:6592) at Function.$$.init (infinitedg_cytoscape.js:75) at cytoscape (infinitedg_cytoscape.js:58) at HTMLDivElement. (infinitedg_cytoscape.js:2808) at Function.jQuery.extend.each (jquery.js:384) at jQuery.fn.jQuery.each (jquery.js:136)

你有一些"hello world" cytoscape 和 meteor 的组合吗?

问题是通过 meteor 安装了错误的库

在我安装正确的 cytoscape 库后,它可以正常工作

正确的是cytoscape:cytoscape

这里是最小的并且可以工作 example:

JS

sit = "" //hlavni objekt

if (Meteor.isClient) {




    Template.graf.rendered = function() {

        // Meteor.defer(function() {
        //setTimeout(function(){

        console.log("on rendered called");
        //var divcy = $('#cy');
        // console.log("ss " + divcy);
        sit = cytoscape({
            container: document.getElementById('cy'),


            ready: function() {
                console.log("network ready");
                updateNetworkData(sit); // load data when cy is ready
            },

            style: cytoscape.stylesheet()
                .selector('node')
                .style({
                    'content': function(e) {
                        return e.data("name")
                    },

                    'font-size': 12,
                    'text-valign': 'center',
                    'color': 'white',
                    'text-outline-width': 2,
                    'text-outline-color': function(e) {
                        return e.locked() ? "red" : "#888"
                    },
                    'min-zoomed-font-size': 8
                        // 'width': 'mapData(score, 0, 1, 20, 50)',
                        // 'height': 'mapData(score, 0, 1, 20, 50)'
                })
                .selector('edge')
                .style({
                    'content': function(e) {
                        return e.data("name") ? e.data("name") : "";
                    },
                    'target-arrow-shape': 'triangle',
                })


        });

        //})
    }




}

if (Meteor.isServer) {
    Meteor.startup(function() {
        // code to run on server at startup
    });
}



function updateNetworkData(net) {

    // init Data

    var nodes = [{ // node a
            group: 'nodes',
            data: {
                id: 'a',
                name:'a'
            }
        }, { // node b
            group: 'nodes',
            data: {
                id: 'b',
              name:'b'
            }
        }

    ]
    var edges = [{ // edge ab
            group: 'edges',
            data: {
                id: 'ab',
              name:'ab',
                source: 'a',
                target: 'b'
            }
        }

    ]

    net.elements().remove(); // make sure evything is clean

    net.add(nodes);
    net.add(edges);

    net.reset() // render layout
}

CSS

#cy {
  width : 70vw;
  height: 50vw;
  position: absolute;
}

HTML

<head>
  <title>hello</title>
</head>

<body>
  <h1>Welcome to Meteor!b</h1>
  {{>graf}}
</body>

<template name="graf">
  <div id="cy"></div>
</template>