How to globally access a variable contained in Editor's "ajax:function()" call?

How to globally access a variable contained in Editor's "ajax:function()" call?

edwardgeyhedwardgeyh Posts: 2Questions: 1Answers: 0

Greetings all,

I am starting with the Editor's Ajax override example: https://editor.datatables.net/examples/advanced/localstorage.html. I use the provided Javascript to define a controller for a custom widget I am building for use on a webpage, I use the example's HTML in its template definition, and the identified JS libraries are loaded as resources. The example works fine in my page.

I then choose to initialize the table from an external variable that I create and supply through the controller "var todo = $scope.properties.tableInput", where "todo" is the variable defined in the example otherwise sourced from localStorage, and this works fine as well.

Now I need to access from outside the instantiated editor the variables defined in its ajax:function(). For example, what I want to realize in the controller is $scope.properties.outputValues = JSON.stringify(output.data) and $scope.properties.outputAction = d.action, where "output" and "d" are the variables defined in the example's script.

I have tried several things but have been unable to progress beyond eyeing the data I want for "Edit" and "New" actions in the console log...

Thanks in advance,
Edward

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,195Questions: 1Answers: 10,412 Site admin
    Answer ✓

    Hi Edward,

    Now I need to access from outside the instantiated editor the variables defined in its ajax:function().

    The best way of doing this is to define a function in your scope that will set the properties (and then take any action you need on them), allowing you to pass them from the ajax function - e.g.:

    ajax: function (method, url, d, successCallback, errorCallback) {
      $scope.myMethod( d.action, d.data );
      ...
    }
    

    Of course it depends on what your $scope object actually is, how you define properties and methods on it, and if it has any reactivity available, but I'd say that this is probably the simplest approach.

    Allan

  • edwardgeyhedwardgeyh Posts: 2Questions: 1Answers: 0

    Allan, thanks for the suggestion. This approach worked fine - after hitting AngularJS over the head with a $scope.$apply().

This discussion has been closed.