10-22-2015 06:16 AM
Hi,
I am playing around for hours now. But whatever I try it does not work.
I would like to load new Topologies from backend system. (REST Interface)
I started with the example from showcase: "Topology with remote Data".
But the propertie defined there is never touched by data...
So I changed my code to a getter and setter methode.
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 topologie 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.
Do I have to clear topo before setting again? If so how can I do that?
Any idea?
Thanks a lot &
Best regards
Markus
An
;
Solved! Go to Solution.
10-22-2015 09:59 AM
Hi Markus.
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");
}
});
10-22-2015 09:59 AM
Hi Markus.
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");
}
});
10-22-2015 10:39 AM
Hello Aleksei,
Thanks a lot for your answer.
This is exactly what I was missing:
var data = JSON.parse(data);
I tried to set a String instead of JSON Object.
Thanks a lot
Best regards
Markus
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide