Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

Get query results - undefined #74

Open
freaksN opened this issue Apr 17, 2018 · 2 comments
Open

Get query results - undefined #74

freaksN opened this issue Apr 17, 2018 · 2 comments

Comments

@freaksN
Copy link

freaksN commented Apr 17, 2018

Whenever I try to get query results before displaying them I either get errors or undefined values.

My code
//Initialize new Query
var A = new sgvizler.Query();

 A.query(" PREFIX dc: <http://purl.org/dc/terms/> PREFIX am: 
  <http://data.linkedmdb.org/resource/movie/actor_name> SELECT ?actorName ?actorLink  WHERE { ? 
   actorLink am: 'Christian Bale' . ?actorLink am: ?actorName . } ")
 .endpointURL("http://data.linkedmdb.org/sparql")
 .endpointOutputFormat("jsonp")
 .chartFunction("sgvizler.visualization.Table")
 .draw("searchResults");
 console.log(A);

Checking the console the first thing that pops out is noOfResults: undefined. Is there way to get the actual value of noOfResults ?

I've also tried to set up dataTable with success and fail functions but I can't access the value of dataTable.getNumberOfRows() outside of the success function.

Is there any fix to this problem ? Or has somebody found a workaround ?

mgskjaeveland added a commit that referenced this issue Apr 18, 2018
@mgskjaeveland
Copy link
Owner

I have cleaned up the code surrounding the noOfResults variable in the develop branch.
However, the log(A) in your code is very likely to always say that noOfResults is undefined as this line is likely to be called before the results are retrieved. (So noOfResults should really be removed.)

This is an example of working with the dataTable asynchronously:
A.getDataTable(function(x) { alert(x.getNumberOfRows());});

The x is the dataTable, and the function gets called on the dataTable once it is ready.

@freaksN
Copy link
Author

freaksN commented Apr 18, 2018

I have cleaned up the code surrounding the noOfResults variable in the develop branch.
However, the log(A) in your code is very likely to always say that noOfResults is undefined as this line is likely to be called before the results are retrieved. (So noOfResults should really be removed.)

This is an example of working with the dataTable asynchronously:
A.getDataTable(function(x) { alert(x.getNumberOfRows());});

The x is the dataTable, and the function gets called on the dataTable once it is ready.

Thank you @mgskjaeveland your suggestion fixes the problem.
I'm using sgVizler in Reactjs and the only thing that you'd need to add to the function in order to have access to value of x outside of the function or to change some states inside of the function(x) is to bind the function like this A.getDataTable(function(x) { alert(x.getNumberOfRows());}.bind(this));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants