我正在尝试从vis.js图中删除一个节点。应用此功能时,不会删除整个节点,也不会删除节点及其向外的边缘。我希望页面刷新后更改保持不变。与此相关的调用是deleteNode
(在index.html中)和app.delete
(在index.js中)。
index.html:
var deleteNode = function(data, callback){
$.ajax({
method: "delete",
url: "/api/node",
data: {node: data.nodes[0] },
success: function(result){
callback(result);
}
})
};
index.js:
app.delete("/api/node", function(req, res){
var deleteNode = req.body.node;
var deleteResult = {
nodes:[],
edges: []
};
var updatedNodes = _.filter(data.nodes, function(node){
var keep = (node.id !== deleteNode);
if(!keep){
deleteResult.nodes.push(node);
}
return keep;
});
var updatedEdges = _.filter(data.edges, function(edge){
var keep = (edge.from !== deleteNode) || (edge.to !== deleteNode);
if(!keep){
deleteResult.edges.push(node);
}
return keep;
});
data.nodes = updatedNodes;
data.edges = updatedEdges;
res.send(deleteResult).end();
});
答案 0 :(得分:0)
您确定您的逻辑正确吗?那是我在这里检查的第一件事。特别是,我看到您的'delete'方法似乎正在返回'deleteResult'变量,该变量可能包含由于API调用而删除的所有节点。也许您想返回“数据”变量呢?