webenginious webenginious - 2 months ago 7
Javascript Question

I can't access my current element

This is an instance of Rappid Toolkit which uses jointJS for building visual tools as for web development. http://i.stack.imgur.com/6XSis.png

In this toolkit you can make a graph which can become a website.

My problem is the following one:

In every single element of this graph there is a box below it with:x,y,width,height,angle.

I want to change this information of this boxcontent and to display some info from this element but the code in which I have to add my snippet is the following(var Halo is the var for my element in the graph):

var halo = new joint.ui.Halo({
cellView: cellView,

boxContent: function(cellView) {


return"Here I want to display my box content info instead of x,y,width,height, angle";
}
}).render();


If I try to add my code inside it to access in JSON format my current element info my full code is:

var halo = new joint.ui.Halo({
cellView: cellView,

boxContent: function(cellView) {
// Drawing
var selectedObjectDataText = JSON.stringify(this.cellView.toJSON());
var selectedObjectDataJSON = JSON.parse(selectedObjectDataText);

return(selectedObjectDataJSON[0].wi_name);
}
}).render();


where wi_name is the name of my element but in the first line I can't access the specific element of my graph.

var selectedObjectDataText = JSON.stringify(this.cellView.toJSON());


Is there any global way to access my halo(my graph element) since this.cellView.toJSON() doesn't work?
I tried this.model.toJSON() this.cellView.model.toJSON() etc with no result

Answer

It worked for var selectedObjectDataText = JSON.stringify(cellView.model.toJSON());

Thank you all for your support.