this reference

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

this reference

media
Hi there,
im a Qooxdoo beginner and i have a problem with the 'this' reference.
How do I get a 'this' reference in a member subfunction (__queryDB)
does anyone have a solution for that?
Thanks!
qx.Class.define("tswmobile.page.BarcodeList",
{
  extend : qx.ui.mobile.page.NavigationPage,

  members :
  {
    _initialize : function()
    {
      this.base(arguments);
      var tlb1 = new qx.ui.mobile.toolbar.ToolBar();
      this.add(tlb1);

      var btn1 = new qx.ui.mobile.toolbar.Button("Button1", "");
      tlb1.add(btn1);

      btn1.addListener("click", function(e)
      {
        this.__helloworld(); // OK
        var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
        db.transaction(this.__queryDB);
      },
      this);
    },

    __queryDB : function(tx) {
      this.__helloworld(); // !!!! PROBLEM !!! this reference  ????
    },

    __helloworld : function() {
      alert("hello world");
    }
  }
});
Reply | Threaded
Open this post in threaded view
|

Re: this reference

Ed Adasiewicz
Without knowing what db.transaction() performs, have you tried replacing

db.transaction(this.__queryDB);

with

db.transaction.call(this, this.__queryDB);

Reply | Threaded
Open this post in threaded view
|

Re: this reference

media
thanks but
the call db.transaction.call(this, this.__queryDB) does not work.

here is the original example of the PhoneGap homepage
http://docs.phonegap.com/en/2.0.0/cordova_storage_storage.md.html#Database
Execute SQL Quick Example :
function populateDB(tx) {
  tx.executeSql('DROP TABLE IF EXISTS DEMO');     
  tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');     
  tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');     
  tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}

function errorCB(err) {
  alert("Error processing SQL: "+err.code);}

function successCB() {    
  alert("success!");}

var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
Reply | Threaded
Open this post in threaded view
|

Re: this reference

Loren Schlomer
Take a look at:
qx.lang.Function.bind()

This will return a function bound with the correct this pointer.

So you'll do something like:

var callback = qx.lang.Function.bind(this.__queryDB, this);

and then use callback:

db.transaction(callback)


http://demo.qooxdoo.org/current/apiviewer/#qx.lang.Function






On Wed, Sep 5, 2012 at 6:42 AM, media <[hidden email]> wrote:

> thanks but
> the call db.transaction.call(this, this.__queryDB) does not work.
>
> here is the original example of the PhoneGap homepage
> http://docs.phonegap.com/en/2.0.0/cordova_storage_storage.md.html#Database
> Execute SQL Quick Example :
>
> function populateDB(tx) {
>   tx.executeSql('DROP TABLE IF EXISTS DEMO');
>   tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
>   tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
>   tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
> }
>
> function errorCB(err) {
>   alert("Error processing SQL: "+err.code);}
>
> function successCB() {
>   alert("success!");}
>
> var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
> db.transaction(populateDB, errorCB, successCB);
>
>
> ________________________________
> View this message in context: Re: this reference
> Sent from the qooxdoo mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: this reference

media
hooray it works!
thank you Loren.

qx.Class.define("tswmobile.page.BarcodeList",
{
  extend : qx.ui.mobile.page.NavigationPage,

  members :
  {
    _initialize : function()
    {
      this.base(arguments);
      var tlb1 = new qx.ui.mobile.toolbar.ToolBar();
      this.add(tlb1);

      var btn1 = new qx.ui.mobile.toolbar.Button("Button1", "");
      tlb1.add(btn1);

      btn1.addListener("click", function(e)
      {
        this.__helloworld(); // OK
        var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
        
        var callback = qx.lang.Function.bind(this.__queryDB, this); 
        db.transaction(callback); 
      },
      this);
    },

    __queryDB : function(tx) {
      this.__helloworld();  // OK  
    },

    __helloworld : function() {
      alert("hello world");
    }
  }
});
Reply | Threaded
Open this post in threaded view
|

Re: this reference

Loren Schlomer
Good!  Glad to help!

On Wed, Sep 5, 2012 at 7:05 AM, media <[hidden email]> wrote:
hooray it works!
thank you Loren.

qx.Class.define("tswmobile.page.BarcodeList",
{
  extend : qx.ui.mobile.page.NavigationPage,

  members :
  {
    _initialize : function()
    {
      this.base(arguments);
      var tlb1 = new qx.ui.mobile.toolbar.ToolBar();
      this.add(tlb1);

      var btn1 = new qx.ui.mobile.toolbar.Button("Button1", "");
      tlb1.add(btn1);

      btn1.addListener("click", function(e)
      {
        this.__helloworld(); // OK
var db = window.openDatabase("Database", "1.0", "Cordova Demo"
, 200000);
var callback = qx.lang.Function.bind(this.__queryDB, this
); db.transaction(callback); }, this); }, __queryDB : function(tx) { this.__helloworld(); // OK }, __helloworld : function() { alert("hello world"); } } });


View this message in context: Re: this reference
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel