3 Replies Latest reply: Jun 26, 2015 3:33 AM by Daniel Cristea RSS

    Script.js syntax for AddExtension()

      I would appreciate some explanation for syntax in Script.js.

       

      function easyQuery_Init() {

          Qv.AddExtension("easyQuery",

              function () {

       

       

                  var _this = this;

                  if (!_this.ExtensionLoaded) {

                      this.ExtensionLoaded = true;

                  }

                  else {

                      //alert('Extension loaded for ' + _this.Layout.ObjectId);

                  }

       

       

                  // Add CSS

                  Qva.LoadCSS(Qva.Remote + (Qva.Remote.indexOf('?') >= 0 ? '&' : '?') + 'public=only' + '&name=' + "Extensions/easyQuery/easyQuery.css");

       

       

                  // Retrieve extension properties

                  setProps();

       

       

                  $(_this.Element).empty();

                  initLoadingPane("Loading data ...");

                  showLoadingPanel("loading data ...");

                  initGrid();

                  initFooter();

                  loadData(data_loaded);

       

      // ...

           }, false);

      }

       

      easyQuery_Init();

       

      First, signature for AddExtension is {void} AddExtension(name, extensionPaint)

       

      What is a paint ? In my example, is function() a paint ? Why is there an additional boolean as a third argument ?

       

      What is this in the statement var _this = this; ?


      What is the general purpose of the Script.js ?

        • Re: Script.js syntax for AddExtension()
          Alexander Karlsson

          Hey,


          I would recommend that you read through the SDK and a few javascript and html tutorials before you venture any further into extensions.


          But yes the AddExtension method takes two required parameters and one optional. The name of the extension, a function that will be invoked on initialization/updates refered to as paint in the QV world. The last bool value defines if the extension should re-paint on updates.



          • Re: Script.js syntax for AddExtension()

            Hello, first I want to apologize for my English.

            The meaning of the assignment "_this = this", is to keep the pointer to the application QlikView and save a copy. Other frameworks like jQuery, JSON, ..., also use the "this" pointer, and if we carry script.js file, we would lose the reference to our QlikView application and could not read the data, call methods or change the properties of the QV API.

            The script.js file, is to give life to our object through javascript. In this file you tell javascript to QlikView are you going to paint on your extension and how you will do. With Properties.qvpp definition.xml and files, you design the form of properties of your extension.

             

            A greeting.