如何使用angularjs更新visjs的节点或边缘属性? [英] How to update a node or edges property of visjs using angularjs?

查看:101
本文介绍了如何使用angularjs更新visjs的节点或边缘属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据某些数据隐藏或取消隐藏某些节点和边缘。我可以通过遍历visjs的数据来实现它,但每次隐藏或取消隐藏时都会触发稳定(这会覆盖现有数据)。



我发现这个例子增加了,通过使用添加更新&直接更改nodes值来更新和删除节点删除功能。这会动态地执行这些操作而不会稳定,但是当我在angularjs中尝试相同的事情时,它表示`org_nodes.update不是函数`



从<来源获取的片段a href =http://visjs.org/examples/network/data/datasets.html>这个例子



  function  addNode(){
var newId =( Math .random()* 1e7).toString( 32 );
nodes.add({id:newId,label: 我是新人! });
nodeIds.push(newId);
}

function changeNode1(){
var newColor = ' #' + 数学 .floor(( Math .random()* 255 * 255 * 255 ))。toString( 16 );
nodes.update([{id: 1 ,color:{background:newColor}}]);
}

function removeRandomNode(){
var randomNodeId = nodeIds [ Math .floor( Math .random()* nodeIds.length)];
nodes.remove({id:randomNodeId});

var index = nodeIds.indexOf(randomNodeId);
nodeIds.splice(index, 1 );
}







请帮助,我提供插件链接在这里我在这里缺少什么?使用 angular-visjs

解决方案

制作节点& edge作为vis.DataSet对象。

 var org_nodes =  new vis.DataSet ([your_nodes]); 
var edges = new vis.DataSet ([your_edges]);



我尝试了你的plunker并且它有效。


I have a requirement to hide or unhide some nodes and edges depending on some data. I can achieve it by traversing through visjs's data but that will trigger stabilization everytime one hides or unhides (this overwrite existing data).

I found this example which adds, updates and removes a node by directly changing `nodes` value by using add, update & remove functions. This dynamically does these operations without stabilizing, but when I try the same thing in angularjs it says `org_nodes.update is not a function`

Snippet taken from source of this example

function addNode() {
        var newId = (Math.random() * 1e7).toString(32);
        nodes.add({id:newId, label:"I'm new!"});
        nodeIds.push(newId);
    }

    function changeNode1() {
        var newColor = '#' + Math.floor((Math.random() * 255 * 255 * 255)).toString(16);
        nodes.update([{id:1, color:{background:newColor}}]);
    }

    function removeRandomNode() {
        var randomNodeId = nodeIds[Math.floor(Math.random() * nodeIds.length)];
        nodes.remove({id:randomNodeId});

        var index = nodeIds.indexOf(randomNodeId);
        nodeIds.splice(index,1);
    }




Please help, I am providing a plunker link here what is it that I am missing here? Using angular-visjs

解决方案

Make your nodes & edges as vis.DataSet objects.

var org_nodes = new vis.DataSet([your_nodes]);
var edges = new vis.DataSet([your_edges]);


I tried on your plunker and it worked.


这篇关于如何使用angularjs更新visjs的节点或边缘属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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