Javascript 为什么$(';#cy';).cytoscape可以工作?
我有以下代码正在使用和。在下面的代码中,Javascript 为什么$(';#cy';).cytoscape可以工作?,javascript,jquery,cytoscape.js,Javascript,Jquery,Cytoscape.js,我有以下代码正在使用和。在下面的代码中,$('#cy').cytoscape是什么意思?我不理解第一部分(即,选择id为cy的元素),但它似乎调用了名为cytoscape的函数,并将一个对象作为其参数传递。jQuery为什么理解这里的cytoscape方法 var init=function () { $('#cy').cytoscape({ elements: [n1,n2,n3,n4,e1,e2], layout: {name: 'preset'}, st
$('#cy').cytoscape
是什么意思?我不理解第一部分(即,选择id为cy的元素),但它似乎调用了名为cytoscape的函数,并将一个对象作为其参数传递。jQuery为什么理解这里的cytoscape方法
var init=function () {
$('#cy').cytoscape({
elements: [n1,n2,n3,n4,e1,e2],
layout: {name: 'preset'},
style: [style1,style2]
});
}
$(init);
这里是完整的代码,只是为了完整;在相应的html页面中有一个id为“cy”的
标记:
var n1={ // node n1
data: { // element data (put dev data here)
id: 'n1', // mandatory for each element, assigned automatically on undefined
parent: 'nparent', // indicates the compound node parent id; not defined => no parent
},
scratch: {
foo: 'bar'
},
position: { // the model position of the node (optional on init, mandatory after)
x: 100,
y: 100
},
selected: false, // whether the element is selected (default false)
selectable: true, // whether the selection state is mutable (default true)
locked: false, // when locked a node's position is immutable (default false)
grabbable: true, // whether the node can be grabbed and moved by the user
classes: 'foo bar' // a space separated list of class names that the element has
};
var n2={ // node n2
data: { id: 'n2' },
renderedPosition: { x: 200, y: 200 } // can alternatively specify position in rendered on-screen pixels
};
var n3={ // node n3
data: { id: 'n3', parent: 'nparent' },
position: { x: 123, y: 234 }
};
var n4=
{ // node nparent
data: { id: 'nparent', position: { x: 200, y: 100 } }
};
var e1={ // edge e1
data: {
id: 'e1',
// inferred as an edge because `source` and `target` are specified:
source: 'n1', // the source node id (edge comes from this node)
target: 'n2' // the target node id (edge goes to this node)
}
};
var e2={ // edge e1
data: {
id: 'e2',
// inferred as an edge because `source` and `target` are specified:
source: 'nparent', // the source node id (edge comes from this node)
target: 'n2' // the target node id (edge goes to this node)
}
};
var style1={
selector: 'node',
style: {
'content': 'data(id)'
}
};
var style2={
selector: ':parent',
style: {
'background-opacity': 0.8
}
};
var init=function () {
$('#cy').css("background-color", "pink");
$('#cy').cytoscape({
elements: [n1,n2,n3,n4,e1,e2],
layout: {name: 'preset'},
style: [style1,style2]
});
}
$(init);
到目前为止,它没有文档记录/不推荐使用,因为它使得获取Cytoscape实例对象更加困难,还有其他原因。它在3.0中不受支持