1

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

5
  • because the function you called (rowCount) dont return anything! Commented Nov 28, 2013 at 10:59
  • btw your return rowCount_i; is never called because of the return obove ;) Commented Nov 28, 2013 at 11:01
  • but i have returned rowCount_I which is having result object. Commented Nov 28, 2013 at 11:01
  • yes but you alert the result of the function not the object! object = alert(tbl); but that will not help you mutch Commented Nov 28, 2013 at 11:02
  • you have still one } missing at the end Commented Nov 28, 2013 at 11:05

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

13 Comments

you cant do it with return, because the plugin also give you a callback. In what way do you want achieve ? Whats your goal ?
My goal is function rowCount should return the result object.
with result object you mean the row count ?
if i do the following code, i did not get the correct result. rowCount : function() { return window.plugins.getRowCount(tableName, function(r) { rowcount_i = r; callback(rowcount_i); } function(e) { alert(e); });
callback is not defined in your code 2 comments above! get your callback like this ? pastebin.com/TSkvr1Wx
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.