我正在尝试使用输入搜索字符串检索具有NEO4J请求(cypher)的节点。当我点击我的按钮搜索时,函数drawGraph()就会启动。我在我的图形容器中看到节点,但它立即消失。
在我的html代码中有一个click事件:
<form>
<input id="inputsearch" type="text" placeholder="Search..">
<button id="buttonsearch" onclick="drawGraph(inputsearch.value)"
type="submit" >Submit</button>
</form>
我的代码如下:
// Neo4j config object
var neo4jConfig = { url: 'http://localhost:7474', user: 'neo4j', password:
'neo4j' };
var inputsearch= document.getElementById('inputsearch');
var buttonSearch=document.getElementById('buttonsearch');
//buttonSearch.addEventListener('click', drawGraph(inputsearch.value));
// function to apply style rules
function applyStyle(s) {
// Node style
s.graph.nodes().forEach(function (node){
if (node.neo4j_labels[0] === "Movie"){
node.label = node.neo4j_data['movie'];
node.color = '#8367C7';
node.size = 16;
node.type = "star";
}
else if (node.neo4j_labels[0] === "Person"){
node.label = node.neo4j_data['person'];
node.type = "diamond";
node.color = '#23CE6B';
node.size = 12;
}
});
// Edge style
s.graph.edges().forEach(function(e) {
e.originalColor = e.color;
e.type = "curvedArrow";
e.size=2;
});
var dragListener = new sigma.plugins.dragNodes(s, s.renderers[0]);
CustomShapes.init(s);
s.refresh();
}
// init sigma
s = new sigma({
renderer: {
container: document.getElementById('graph-container'),
type: 'canvas'
}
});
CustomShapes.init(s);
s.refresh();
s.bind("doubleClickNode", function(e) {
var node = e.data.node;
var query = 'MATCH (n)-[r]-(m) WHERE id(n)=' + node.id+ ' RETURN n,r,m';
sigma.neo4j.cypher(
neo4jConfig,
query,
function(graph) {
// adding node if not existing
graph.nodes.forEach(function (node){
if(s.graph.nodes(node.id) === undefined) {
s.graph.addNode(node);
}
});
// adding edge if not existing
graph.edges.forEach(function (edge){
if(s.graph.edges(edge.id) === undefined) {
s.graph.addEdge(edge);
}
});
// apply style
applyStyle(s);
}
);
});
// display cypher query
sigma.neo4j.cypher(
neo4jConfig,
'MATCH (n) OPTIONAL MATCH (n)-[r]->(m) RETURN n,r,m LIMIT 1',
s,
applyStyle
);
function drawGraph(inputsearch){
sigma.neo4j.cypher(neo4jConfig,
'match (n:Person)-[r]->(m) where n.nom =~ "(?i).*' + inputsearch + '.*"
return n LIMIT 1;',
s,
applyStyle)
};
CustomShapes.init(s);
s.refresh();
任何人都可以帮助我吗?