简体   繁体   中英

how to return result in phonegap javascript function?

Hi I'm trying to return the result from the phonegap plugin method.

I'like to do the following code.

  function table(tableName)
  {
        var rowCount_i;
        return {
                 tableName : tableName,
                 rowCount : function(){
                 window.plugins.getRowCount(
                                   tableName,
                  function(r)
                  {
                         rowcount_i = r; 
                  }
                  function(e)
                  {
                          alert(e); 
                  }

        );
        return rowCount_i;

     }
 };

 }

When i'm tried to run the following code...

  var tbl = new table("psd-person");
  alert(tbl.rowCount);

And the result is Undefined..

Is there any way to return the result in rowCount Method or can you show this rowCount method with defferd concept?

Please help me out.. Thanks in advance

try it with callback:

function table(tableName)
{
  return {
    tableName : tableName,
    rowCount : function(callback){
      window.plugins.getRowCount(tableName,
        function(r)
        {
               rowcount_i = r; 
               callback(rowcount_i);
        }
        function(e)
        {
                alert(e); 
        });    
    }
  }
}

var tbl = new table("psd-person");
tbl.rowCount(function(rowcount_i) {
  alert(rowcount_i);
});

Not tested!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM