- Would like to load a new Topology from back end system. (REST Interface). Started with the example from showcase: "Topology with remote Data". But the properties defined there is never touched by data...
So changed the code to a getter and setter method..
methods: { getTopo: function() { var result = this.view('topo').getData(); return result; }, setTopo: function (newTopo) { this.view('topo').data(newTopo); var c = this.getTopo(); } }
When calling this function on app start everything works fine:
(function (nx) { var App = nx.define(nx.ui.Application, { methods: { start: function() { node = new Tooltip.Node(); node.setTopo(initDataAlt); var model = new com.cisco.TopologyModel(); node.attach(this); node.model(model); } } }); new App().start(); })(nx);
- But when calling the setter from JavaScript Button Action to load a new Topology nothing happens.
- In Variable "newTopo" there is the new topologies loaded BUT in variable "c" there is still the old topology.
- If changing the call to: "this.view('topo').setData(newTopo)" does not change anything.
- Is it needed to clear topo before setting again. If so how to do it.
It's a better idea to use 'getTopo' to get the topology instance instead of getting topology data. In this case you're gonna have something like that:
methods: { 'getTopo': function(){ return this.view('topo'); }
You'll be able to use any methods of nx.graphic.Topology class just having invoked .getTopo():
1. to update topology data: topologyContainer.getTopo().data(newTopo);
2. to read exisiting data: topologyContainer.getTopo().data();
Of course, you can also assign topologyContainer.getTopo() reference to a variable, like that...
var topo = topologyContainer.getTopo();
... and then use it, like that:
var topo = topologyContainer.getTopo(); $.ajax({ type: 'GET', url: 'http://example.com/topology', dataType: 'json', // ... some other config ... success: function(data){ // use try/catch to track parsing errors try { var data = JSON.parse(data); topo.data(data); } catch(SyntaxError){ alert('hey, json is broken'); } }, error: function(jqXHR, exception){ // some http erorr stuff alert("couldn't get topology from the server"); } });
Comments
0 comments
Please sign in to leave a comment.